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

fix: Use buffered reader in peer to fix ShortBuffer #303

Merged
merged 3 commits into from
Feb 17, 2022
Merged

Conversation

kylecarbs
Copy link
Member

@kylecarbs kylecarbs commented Feb 16, 2022

This prevents a io.ErrShortBuffer from occurring when the byte
slice being read is smaller than the chunks sent from the opposite
pipe.

This makes sense for unordered connections, where transmission is
not guaranteed, but does not make sense for TCP-like connections.

We use a bufio.Reader when ordered to ensure data isn't lost.

@kylecarbs kylecarbs self-assigned this Feb 16, 2022
This prevents a io.ErrShortBuffer from occurring when the byte
slice being read is smaller than the chunks sent from the opposite
pipe.

This makes sense for unordered connections, where transmission is
not guaranteed, but does not make sense for TCP-like connections.

We use a bufio.Reader when ordered to ensure data isn't lost.
@codecov
Copy link

codecov bot commented Feb 16, 2022

Codecov Report

Merging #303 (2b411ae) into main (deb7170) will decrease coverage by 0.10%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #303      +/-   ##
==========================================
- Coverage   67.85%   67.75%   -0.11%     
==========================================
  Files         135      135              
  Lines        7149     7154       +5     
  Branches       73       73              
==========================================
- Hits         4851     4847       -4     
- Misses       1809     1815       +6     
- Partials      489      492       +3     
Flag Coverage Δ
unittest-go-macos-latest 66.09% <50.00%> (-0.09%) ⬇️
unittest-go-ubuntu-latest 67.18% <50.00%> (+0.11%) ⬆️
unittest-go-windows-latest 65.94% <50.00%> (+0.02%) ⬆️
unittest-js 64.61% <ø> (ø)
Impacted Files Coverage Δ
peer/channel.go 83.43% <50.00%> (-1.33%) ⬇️
peerbroker/dial.go 76.19% <0.00%> (-4.77%) ⬇️
peer/conn.go 78.97% <0.00%> (-0.52%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update deb7170...2b411ae. Read the comment docs.

// When ordered, this adds a bufio.Reader. This ensures additional
// data on TCP-like connections can be read in parts, while still
// being bufferred.
if c.opts.Unordered {
Copy link
Contributor

Choose a reason for hiding this comment

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

ooo, wonder if we have the same issue with wsnet 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

I was really confused why wsnet doesn't have this problem, but I think it's because we pipe using net.Dial for everything. So the problem exists, but it's hidden behind the TCP buffering there maybe?

ssh is a specific protocol in the agent, so we're exchanging much smaller payloads here, which made me notice this bug.

Copy link
Contributor

Choose a reason for hiding this comment

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

for context, I was getting weird short buffer errors (that I had no idea how to reproduce easily or diagnose) when I tried to remove the envagent proxying, so I wonder whether this would've fixed it

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, this almost certainly would have!

Comment on lines +142 to +144
// When ordered, this adds a bufio.Reader. This ensures additional
// data on TCP-like connections can be read in parts, while still
// being bufferred.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for documenting this, very helpful. Wouldn't have been clear to me why we need this otherwise 👍

Copy link
Contributor

@bryphe-coder bryphe-coder left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for catching this and fixing it @kylecarbs

// When ordered, this adds a bufio.Reader. This ensures additional
// data on TCP-like connections can be read in parts, while still
// being bufferred.
if c.opts.Unordered {
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious if we use unordered connections via WebRTC in the product today?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nah, we don't!

@kylecarbs kylecarbs merged commit d436993 into main Feb 17, 2022
@kylecarbs kylecarbs deleted the buffered branch February 17, 2022 14:45
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

3 participants