Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

More informative error message if no protocol found for http2 #305

Merged
merged 1 commit into from
Jan 24, 2017

Conversation

ojii
Copy link
Contributor

@ojii ojii commented Jan 24, 2017

Today I ran into an issue with hyper, where the OpenSSL version in my environment was too old (1.0.1) so it did not have ALPN, which was required by the server. This is of course not a bug/problem with hyper itself, however the error message I got from hyper was not that helpful (it was an AssertionError with no help message). This pull request suggests a new check after wrapping the socket in SSL to see if a protocol was selected and if not tells the user that none was selected and suggests the user check their OpenSSL version.

@Lukasa
Copy link
Member

Lukasa commented Jan 24, 2017

@ojii Thanks for this patch, this looks like a good change. Do you mind adding a test to confirm that the message is present? That way we won't accidentally regress it.

@ojii
Copy link
Contributor Author

ojii commented Jan 24, 2017

@Lukasa will try. Had issues running the test suite (related to my network setup, not the test suite itself from what I can see), which is why there's no test included for now.

@ojii
Copy link
Contributor Author

ojii commented Jan 24, 2017

@Lukasa I've added a test, though I had to mock out all of wrap_socket. I hope this is okay.

Copy link
Member

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

This is generally fine, just got a pair of notes here.

"No suitable protocol found, check your OpenSSL version"
in
str(exc_info)
)
Copy link
Member

Choose a reason for hiding this comment

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

You can pull this assertion out of the context manager, which you will in fact need to do to get it to run because the AssertionError that gets thrown terminates the execution of this block.

str(exc_info)
)

self.tear_down()
Copy link
Member

Choose a reason for hiding this comment

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

Newline at the end of the file please! =)

@ojii
Copy link
Contributor Author

ojii commented Jan 24, 2017

Looks like https://github.com/ojii/hyper/blob/bdcf38e403c1f669d8d66d760ad16ee4c7153451/test/test_integration.py#L38breaks the other tests. proto becomes None in wrap_socket, but the next assertion that proto is in H2_NPN_PROTOCOLS passes because None is allowed.

Of course with my extra check, this fails now with the explicit check against None.

Not sure what the best way to proceed is.

@Lukasa
Copy link
Member

Lukasa commented Jan 24, 2017

So, is there any reason not to extend the assertion below rather than add a new one? If not, you should assert that the protocol is in H2_NPN_PROTOCOLS.

Copy link
Member

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Looks like a comment got moved.

PROTOCOLS = hyper.http20.connection.H2_NPN_PROTOCOLS + ['', None]


# Cover our bases because NPN doesn't yet work on all our test platforms.
Copy link
Member

Choose a reason for hiding this comment

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

Why did this get moved?

@ojii
Copy link
Contributor Author

ojii commented Jan 24, 2017

Looks like a comment got moved.

Really sorry about how messy this pull request got. Should I re-open another PR with the changes as one commit?

@Lukasa
Copy link
Member

Lukasa commented Jan 24, 2017

There's no need: if you rebase the branch to squash the commits down and then force push to the same branch, GitHub will work it out. =D

Added a more informative error message if a HTTP2 connection was unable
to select a protocol, added a test for this error message.
Changed integration tests to use mock to override acceptable protocols,
so as not to leak those changes to other tests.
@ojii ojii force-pushed the more-helpful-error-message branch from ade560c to 5e133b6 Compare January 24, 2017 13:57
@ojii
Copy link
Contributor Author

ojii commented Jan 24, 2017

I hope it's fine now. Let me know if there's any other changes that are needed.

@Lukasa
Copy link
Member

Lukasa commented Jan 24, 2017

Looks good to me. Good work @ojii! ✨

@Lukasa Lukasa merged commit 28bfaba into python-hyper:development Jan 24, 2017
@ojii ojii deleted the more-helpful-error-message branch January 24, 2017 15:43
@ojii
Copy link
Contributor Author

ojii commented Jan 24, 2017

Thank you for your great work bringing HTTP2 to Python.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants