narrow except around socket.getpeername to OSError in SSL handshake handler#3641
Open
HrachShah wants to merge 1 commit into
Open
narrow except around socket.getpeername to OSError in SSL handshake handler#3641HrachShah wants to merge 1 commit into
HrachShah wants to merge 1 commit into
Conversation
…andler The handler at the SSL_ERROR_SSL/SSL_ERROR_SYSCALL branch of the handshake error path wraps self.socket.getpeername() in a try/except Exception that falls back to the literal string '(not connected)'. getpeername() only raises OSError and its subclasses (ENOTCONN when the socket is not yet connected, EBADF when the fd is no longer valid, ENOTSOCK for a bad file descriptor). It does not raise any other Exception type. Narrowing the handler to OSError lets a real bug in our own code (AttributeError from a typo on self.socket, NameError after a partial module reload, TypeError from a wrong type passed in) surface as a diagnostic instead of being swallowed and silently replaced with the '(not connected)' fallback string, which then gets logged as the peer address for a real peer that we just lost the ability to look up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
narrow except around socket.getpeername to OSError in SSL handshake handler
The handler at the SSL_ERROR_SSL/SSL_ERROR_SYSCALL branch of the
handshake error path wraps self.socket.getpeername() in a
try/except Exception that falls back to the literal string
'(not connected)'. getpeername() only raises OSError and its
subclasses (ENOTCONN when the socket is not yet connected,
EBADF when the fd is no longer valid, ENOTSOCK for a bad
file descriptor). It does not raise any other Exception type.
Narrowing the handler to OSError lets a real bug in our own
code (AttributeError from a typo on self.socket, NameError
after a partial module reload, TypeError from a wrong type
passed in) surface as a diagnostic instead of being
swallowed and silently replaced with the '(not connected)'
fallback string, which then gets logged as the peer address
for a real peer that we just lost the ability to look up.