From f756737dceca945626f3d3dbeedf69566f32e66f Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 2 Sep 2020 12:09:06 +0300 Subject: [PATCH] bpo-40352: Try to reconnect socket when send message in SocketHandler. --- Lib/logging/handlers.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 867ef4ebc7600a0..042c4f8a9197227 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -582,17 +582,24 @@ def send(self, s): This function allows for partial sends which can happen when the network is busy. """ - if self.sock is None: - self.createSocket() - #self.sock can be None either because we haven't reached the retry - #time yet, or because we have reached the retry time and retried, - #but are still unable to connect. - if self.sock: + attempt = True + while True: + if self.sock is None: + attempt = False + self.createSocket() + # self.sock can be None either because we haven't reached the retry + # time yet, or because we have reached the retry time and retried, + # but are still unable to connect. + if self.sock is None: + break try: self.sock.sendall(s) except OSError: #pragma: no cover self.sock.close() self.sock = None # so we can call createSocket next time + if attempt: + continue + break def makePickle(self, record): """