Skip to content

Commit

Permalink
bpo-30329: Catch Windows error 10022 on shutdown() (#1538) (#1624)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
vstinner authored May 17, 2017
1 parent b8b9f95 commit 800e4b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Lib/imaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ def shutdown(self):
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()
Expand Down
4 changes: 4 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down

0 comments on commit 800e4b7

Please sign in to comment.