summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-05-16 17:38:30 -0700
committerGitHub <noreply@github.com>2017-05-16 17:38:30 -0700
commit800e4b7ad6b6f86c17408429852dfb47493d366e (patch)
treea950f39d0462fee5a3c7ff1df9d7ae7d0783aa30
parentb8b9f95f660d00ce9bd11bd9de429176858be3c5 (diff)
downloadcpython-git-800e4b7ad6b6f86c17408429852dfb47493d366e.tar.gz
bpo-30329: Catch Windows error 10022 on shutdown() (#1538) (#1624)
Catch the Windows socket WSAEINVAL error (code 10022) in imaplib on shutdown(SHUT_RDWR): An invalid operation was attempted This error occurs sometimes on SSL connections. (cherry picked from commit 83a2c2879839da2e10037f5e4af1bd1dafbf1a52)
-rw-r--r--Lib/imaplib.py6
-rw-r--r--Misc/NEWS4
2 files changed, 8 insertions, 2 deletions
diff --git a/Lib/imaplib.py b/Lib/imaplib.py
index f813ece8bd..220d6e1bc0 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -264,8 +264,10 @@ class IMAP4:
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:
+ # The server might already have closed the connection.
+ # On Windows, this may result in WSAEINVAL (error 10022):
+ # An invalid operation was attempted.
+ if e.errno not in (errno.ENOTCONN, 10022):
raise
finally:
self.sock.close()
diff --git a/Misc/NEWS b/Misc/NEWS
index 059f2b3086..c3fb3c8900 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -42,6 +42,10 @@ Extension Modules
Library
-------
+- bpo-30329: imaplib now catchs the Windows socket WSAEINVAL error
+ (code 10022) on shutdown(SHUT_RDWR): An invalid operation was attempted.
+ This error occurs sometimes on SSL connections.
+
- bpo-30342: Fix sysconfig.is_python_build() if Python is built with Visual
Studio 2008 (VS 9.0).