Repository navigation
Fix implementation of available() in sockets - #694
Merged
Merged
Conversation
The file descriptor socket used the default implementation of available(), which just always returns 0. We can at least return the pending bytes in the plaintext buffer, since those are definitely available. The engine socket had two issues. First, it used fromSocket.remaining(), but fromSocket was in a writing posture, so it always had a high return from remaining() regardless of whether there was pending readable data in the buffer. This was the cause of google#433: a BufferedReader would read some data, then check available() to see if it could freely fill some more data without blocking. The engine socket would report that it could, so it would try to read that data and then unexpectedly block. The second issue is that incoming socket data doesn't necessarily imply readable plaintext data: it might be a partial TLS record, a handshake or other management record, etc. So we should only report plaintext data that's actually been successfully decrypted from available(). Fixes google#433
prbprbprb
approved these changes
Aug 2, 2019
|
Great explanation in the PR description, thanks! |
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.
The file descriptor socket used the default implementation of
available(), which just always returns 0. We can at least return the
pending bytes in the plaintext buffer, since those are definitely
available.
The engine socket had two issues. First, it used
fromSocket.remaining(), but fromSocket was in a writing posture, so it
always had a high return from remaining() regardless of whether there
was pending readable data in the buffer. This was the cause of #433:
a BufferedReader would read some data, then check available() to see
if it could freely fill some more data without blocking. The engine
socket would report that it could, so it would try to read that data
and then unexpectedly block.
The second issue is that incoming socket data doesn't necessarily
imply readable plaintext data: it might be a partial TLS record, a
handshake or other management record, etc. So we should only report
plaintext data that's actually been successfully decrypted from
available().
Fixes #433