]> granicus.if.org Git - python/commitdiff
bpo-30329: Catch Windows error 10022 on shutdown() (#1538) (#1624)
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 17 May 2017 00:38:30 +0000 (17:38 -0700)
committerGitHub <noreply@github.com>
Wed, 17 May 2017 00:38:30 +0000 (17:38 -0700)
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)

Lib/imaplib.py
Misc/NEWS

index f813ece8bd481d0671e81797bf809d973714282e..220d6e1bc0a669f7caa796fce387259adc860ef2 100644 (file)
@@ -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()
index 059f2b3086021be4d3b0ca443c0aac211dd10b7b..c3fb3c8900f5ca2405ea5bd32e59b1fc083aed44 100644 (file)
--- 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).