Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d89824b

Browse files
committed
Issue #4473: Ensure the socket is shutdown cleanly in POP3.close().
Patch by Lorenzo Catucci.
1 parent ff790aa commit d89824b

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

Lib/poplib.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,14 @@ def close(self):
259259
if self.file is not None:
260260
self.file.close()
261261
if self.sock is not None:
262-
self.sock.close()
262+
try:
263+
self.sock.shutdown(socket.SHUT_RDWR)
264+
except socket.error as e:
265+
# The server might already have closed the connection
266+
if e.errno != errno.ENOTCONN:
267+
raise
268+
finally:
269+
self.sock.close()
263270
self.file = self.sock = None
264271

265272
#__del__ = quit

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ Core and Builtins
138138
Library
139139
-------
140140

141+
- Issue #4473: Ensure the socket is shutdown cleanly in POP3.close().
142+
Patch by Lorenzo Catucci.
143+
141144
- Issue #16522: added FAIL_FAST flag to doctest.
142145

143146
- Issue #15627: Add the importlib.abc.SourceLoader.compile_source() method.

0 commit comments

Comments
 (0)