From 22e9ccb3876112da231a4c89f7d3882e8ffdaaf9 Mon Sep 17 00:00:00 2001 From: sebres Date: Mon, 9 Apr 2018 14:19:48 +0200 Subject: [PATCH] amend to 5f021aa648c42ee188d8c31a81937d764982a58a: void throw a socket error on shutdown for already closed connection; closes gh-2109 --- fail2ban/client/csocket.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fail2ban/client/csocket.py b/fail2ban/client/csocket.py index ce01ae08..3b48e507 100644 --- a/fail2ban/client/csocket.py +++ b/fail2ban/client/csocket.py @@ -43,7 +43,7 @@ class CSocket: self.__csock.connect(sock) def __del__(self): - self.close(False) + self.close() def send(self, msg, nonblocking=False, timeout=None): # Convert every list member to string @@ -56,13 +56,18 @@ class CSocket: def settimeout(self, timeout): self.__csock.settimeout(timeout if timeout != -1 else self.__deftout) - def close(self, sendEnd=True): + def close(self): if not self.__csock: return - if sendEnd: + try: self.__csock.sendall(CSPROTO.CLOSE + CSPROTO.END) - self.__csock.shutdown(socket.SHUT_RDWR) - self.__csock.close() + self.__csock.shutdown(socket.SHUT_RDWR) + except socket.error: # pragma: no cover - normally unreachable + pass + try: + self.__csock.close() + except socket.error: # pragma: no cover - normally unreachable + pass self.__csock = None @staticmethod