Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-30329: Catch Windows error 10022 on shutdown() #1538

Merged
merged 1 commit into from
May 15, 2017
Merged

bpo-30329: Catch Windows error 10022 on shutdown() #1538

merged 1 commit into from
May 15, 2017

Conversation

vstinner
Copy link
Member

Catch the Windows socket error 10022 (An invalid operation was
attempted) on shutdown(SHUT_RDWR) in imaplib and poplib. This error
occurs sometimes on SSL connections.

@mention-bot
Copy link

@Haypo, thanks for your PR! By analyzing the history of the files in this pull request, we identified @tim-one, @tiran and @bitdancer to be potential reviewers.

@vstinner vstinner requested review from tiran and bitdancer May 10, 2017 16:51
Lib/imaplib.py Outdated
if e.errno != errno.ENOTCONN:
except OSError as exc:
# The server might already have closed the connection.
# Windows error 10022: An invalid operation was attempted.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change the comment to "On Windows, this may result in Windows error 10022: An invalid operation was attempted". At least, I hope that's why we're getting that error. (In my experience invalid operation is indeed what windows raises when you attempt an operation on a closed socket).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(In my experience invalid operation is indeed what windows raises when you attempt an operation on a closed socket).

I failed to reproduce the error on Windows on a closed socket. If the socket is closed, its socket handle becomes -1. Calling shutdown() with the socket handle -1 is not a good idea. It would be better to raise an exception rather than calling shutdown() if the socket is known to be closed, but I'm too shy to propose such change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change the comment to "On Windows, this may result in Windows error 10022: An invalid operation was attempted".

Done

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.
@vstinner vstinner merged commit 83a2c28 into python:master May 15, 2017
@vstinner vstinner deleted the shutdown_10022 branch May 15, 2017 15:33
vstinner added a commit that referenced this pull request May 16, 2017
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.
(cherry picked from commit 83a2c28)
vstinner added a commit that referenced this pull request May 16, 2017
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.
(cherry picked from commit 83a2c28)
vstinner added a commit that referenced this pull request May 17, 2017
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants