Navigation Menu

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

Rework Ssl*Stream creation. #1109

Merged
merged 2 commits into from Jan 27, 2023
Merged

Conversation

prbprbprb
Copy link
Collaborator

PR #1106 introduced a subtle bug by changing SslStream creation to use the public getStream() methods.

The contract for those methods is to throw if the socket has been closed, which mean two threads could race such that startHandshake() called getInputStream() after the socket has been closed by another (e.g. timeout) thread. The upshot was that getInputStream() would throw, causing close() to be called before an output stream is created, causing an NPE when trying to send a TLS close message.

This change moves the actual creation into a method which doesn't chack the socket state and so is suitable for calling from startHandshake().

Also added some additional tests around shutdownInput() and shutdownOutput() as it became apparent these were missing.

PR google#1106 introduced a subtle bug by changing Ssl*Stream
creation to use the public get*Stream() methods.

The contract for those methods is to throw if the socket has been
closed, which mean two threads could race such that
startHandshake() called getInputStream() after the socket has
been closed by another (e.g. timeout) thread.  The upshot was
that getInputStream() would throw, causing close() to be called
before an output stream is created, causing an NPE when trying to
send a TLS close message.

This change moves the actual creation into a method which doesn't
chack the socket state and so is suitable for calling from
startHandshake().

Also added some additional tests around shutdownInput() and
shutdownOutput() as it became apparent these were missing.
@prbprbprb prbprbprb merged commit 95333de into google:master Jan 27, 2023
@prbprbprb prbprbprb deleted the socket_close_nullprt branch January 27, 2023 18:32
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.

None yet

2 participants