From: Antoine Pitrou Date: Fri, 23 Nov 2012 19:04:45 +0000 (+0100) Subject: Issue #4473: Ensure the socket is shutdown cleanly in POP3.close(). X-Git-Tag: v3.4.0a1~1954^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d89824b0e2fa9a44b56394a5185de737a6527ea7;p=python Issue #4473: Ensure the socket is shutdown cleanly in POP3.close(). Patch by Lorenzo Catucci. --- diff --git a/Lib/poplib.py b/Lib/poplib.py index d42d9dd320..094aaa11b3 100644 --- a/Lib/poplib.py +++ b/Lib/poplib.py @@ -259,7 +259,14 @@ class POP3: if self.file is not None: self.file.close() if self.sock is not None: - self.sock.close() + try: + self.sock.shutdown(socket.SHUT_RDWR) + except socket.error as e: + # The server might already have closed the connection + if e.errno != errno.ENOTCONN: + raise + finally: + self.sock.close() self.file = self.sock = None #__del__ = quit diff --git a/Misc/NEWS b/Misc/NEWS index 10a07cda24..917f4d5496 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -138,6 +138,9 @@ Core and Builtins Library ------- +- Issue #4473: Ensure the socket is shutdown cleanly in POP3.close(). + Patch by Lorenzo Catucci. + - Issue #16522: added FAIL_FAST flag to doctest. - Issue #15627: Add the importlib.abc.SourceLoader.compile_source() method.