summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-05-15 15:33:45 (GMT)
committerGitHub <noreply@github.com>2017-05-15 15:33:45 (GMT)
commit83a2c2879839da2e10037f5e4af1bd1dafbf1a52 (patch)
treeef24c8005deb9f83be79420446dbbd779af4a68f
parentedef358ed6d05f927bf1636cc5a920a9d868b131 (diff)
downloadcpython-83a2c2879839da2e10037f5e4af1bd1dafbf1a52.zip
cpython-83a2c2879839da2e10037f5e4af1bd1dafbf1a52.tar.gz
cpython-83a2c2879839da2e10037f5e4af1bd1dafbf1a52.tar.bz2
bpo-30329: Catch Windows error 10022 on shutdown() (#1538)
Catch the Windows socket WSAEINVAL error (code 10022) in imaplib and poplib on shutdown(SHUT_RDWR): An invalid operation was attempted This error occurs sometimes on SSL connections.
-rw-r--r--Lib/imaplib.py9
-rw-r--r--Lib/poplib.py9
-rw-r--r--Misc/NEWS4
3 files changed, 16 insertions, 6 deletions
diff --git a/Lib/imaplib.py b/Lib/imaplib.py
index 2fa9012..1c0b03b 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -318,9 +318,12 @@ class IMAP4:
self.file.close()
try:
self.sock.shutdown(socket.SHUT_RDWR)
- except OSError as e:
- # The server might already have closed the connection
- if e.errno != errno.ENOTCONN:
+ except OSError as exc:
+ # The server might already have closed the connection.
+ # On Windows, this may result in WSAEINVAL (error 10022):
+ # An invalid operation was attempted.
+ if (exc.errno != errno.ENOTCONN
+ and getattr(exc, 'winerror', 0) != 10022):
raise
finally:
self.sock.close()
diff --git a/Lib/poplib.py b/Lib/poplib.py
index cae6950..6bcfa5c 100644
--- a/Lib/poplib.py
+++ b/Lib/poplib.py
@@ -288,9 +288,12 @@ class POP3:
if sock is not None:
try:
sock.shutdown(socket.SHUT_RDWR)
- except OSError as e:
- # The server might already have closed the connection
- if e.errno != errno.ENOTCONN:
+ except OSError as exc:
+ # The server might already have closed the connection.
+ # On Windows, this may result in WSAEINVAL (error 10022):
+ # An invalid operation was attempted.
+ if (exc.errno != errno.ENOTCONN
+ and getattr(exc, 'winerror', 0) != 10022):
raise
finally:
sock.close()
diff --git a/Misc/NEWS b/Misc/NEWS
index a874d03..9583149 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -323,6 +323,10 @@ Extension Modules
Library
-------
+- bpo-30329: imaplib and poplib now catch the Windows socket WSAEINVAL error
+ (code 10022) on shutdown(SHUT_RDWR): An invalid operation was attempted.
+ This error occurs sometimes on SSL connections.
+
- bpo-29196: Removed previously deprecated in Python 2.4 classes Plist, Dict
and _InternalDict in the plistlib module. Dict values in the result of
functions readPlist() and readPlistFromBytes() are now normal dicts. You