Skip to content

Commit 800e4b7

Browse files
authored
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 83a2c28)
1 parent b8b9f95 commit 800e4b7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Lib/imaplib.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,10 @@ def shutdown(self):
264264
try:
265265
self.sock.shutdown(socket.SHUT_RDWR)
266266
except socket.error as e:
267-
# The server might already have closed the connection
268-
if e.errno != errno.ENOTCONN:
267+
# The server might already have closed the connection.
268+
# On Windows, this may result in WSAEINVAL (error 10022):
269+
# An invalid operation was attempted.
270+
if e.errno not in (errno.ENOTCONN, 10022):
269271
raise
270272
finally:
271273
self.sock.close()

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ Extension Modules
4242
Library
4343
-------
4444

45+
- bpo-30329: imaplib now catchs the Windows socket WSAEINVAL error
46+
(code 10022) on shutdown(SHUT_RDWR): An invalid operation was attempted.
47+
This error occurs sometimes on SSL connections.
48+
4549
- bpo-30342: Fix sysconfig.is_python_build() if Python is built with Visual
4650
Studio 2008 (VS 9.0).
4751

0 commit comments

Comments
 (0)