]> granicus.if.org Git - python/commitdiff
Issue #4473: Ensure the socket is shutdown cleanly in POP3.close().
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 23 Nov 2012 19:04:45 +0000 (20:04 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 23 Nov 2012 19:04:45 +0000 (20:04 +0100)
Patch by Lorenzo Catucci.

Lib/poplib.py
Misc/NEWS

index d42d9dd32024ac97c841cd03a87852c7c2ba4a5e..094aaa11b3fe4b463f62abf2fa007612ec965100 100644 (file)
@@ -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
index 10a07cda24176915ee3a0419fe078e897fbb5005..917f4d549670e7bc60bd1dd89592734589052101 100644 (file)
--- 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.