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

Wrap SSL sockets after connecting #1754

Merged
merged 1 commit into from
Mar 22, 2019
Merged

Wrap SSL sockets after connecting #1754

merged 1 commit into from
Mar 22, 2019

Conversation

dpkp
Copy link
Owner

@dpkp dpkp commented Mar 21, 2019

Fix for #1741 . Previously we have been wrapping sockets with an SSLContext before connection, and calling connect_ex to do a non-blocking connect, then calling do_handshake. But the TCP connect itself does not require the SSLContext, and it appears that in general, and definitely on python3.7, non-blocking connect_ex w/ ssl sockets is not fully supported.

So this PR defers wrap_ssl until after the TCP socket is connected, which should side-step all of the ValueError / OSError issues raised by python3.7 due to poor support for connect_ex. Also it is simpler, which I like.


This change is Reviewable

Copy link
Contributor

@jeffwidman jeffwidman left a comment

Choose a reason for hiding this comment

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

Very nicely done. Had not thought of that solution.

@@ -486,9 +481,6 @@ def _try_handshake(self):
# old ssl in python2.6 will swallow all SSLErrors here...
except (SSLWantReadError, SSLWantWriteError):
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this also check whether python < 2.7 before pass'ing? Just in the off-chance these exceptions get-used later?

Copy link
Owner Author

Choose a reason for hiding this comment

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

no, see the import hackery above. this is an old problem. we could try to check exception error codes etc, but unless there's a real user asking for help w/ old python installs I'm not that interested in adding more compatibility layers here.

Plus python 2.7 is EOL very soon...

@dpkp dpkp merged commit f2f2bfe into master Mar 22, 2019
@dpkp dpkp deleted the wrap_ssl_after_connect branch March 22, 2019 03:10
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.

2 participants