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

protocol: avoid double buffering #116

Merged
merged 4 commits into from
Oct 8, 2024

Conversation

mmatczuk
Copy link
Contributor

Use smaller buffer size, and use buffer only to read the PROXY header.

Users may use they own buffers with they own buffer sizes and pools - connection should respect that.

mmatczuk added a commit to saucelabs/forwarder that referenced this pull request Sep 17, 2024
The mod file contains replace directive to include my fixes to the library [1].

[1] pires/go-proxyproto#116
@pires pires self-assigned this Sep 17, 2024
@coveralls
Copy link

coveralls commented Sep 17, 2024

Coverage Status

coverage: 94.111% (-0.5%) from 94.606%
when pulling ccf1e75 on mmatczuk:mmt/dont_use_read_buffer
into 9814f02 on pires:main.

@mmatczuk mmatczuk force-pushed the mmt/dont_use_read_buffer branch from b4098fd to 45b522d Compare September 18, 2024 10:00
@mmatczuk
Copy link
Contributor Author

mmatczuk commented Sep 18, 2024

I fixed the linting issues in the patch, and piggybacked patch to fix the ioutil usage.

@pires
Copy link
Owner

pires commented Sep 18, 2024

Hey there! Thank you for your contribution. Would you be so kind as to check the tests failure? https://github.com/pires/go-proxyproto/actions/runs/10919900083/job/30323349143?pr=116#step:5:194

@mmatczuk mmatczuk force-pushed the mmt/dont_use_read_buffer branch from 45b522d to f7fa186 Compare September 19, 2024 08:05
@mmatczuk
Copy link
Contributor Author

Sure, it's done.

@pires
Copy link
Owner

pires commented Oct 8, 2024

I am paying attention to this but I need #110 to land first 🙏🏻 thanks for your patience.

@pires
Copy link
Owner

pires commented Oct 8, 2024

Actually, I'm merging this now. Thanks a lot for your contribution.

This field order reflect usage pattern and avoids mixing exported and unexported fields.
Use buffer only to read the PROXY header.
Users may use they own buffers with they own buffer sizes and pools - connection should respect that.
@pires pires force-pushed the mmt/dont_use_read_buffer branch from f7fa186 to ccf1e75 Compare October 8, 2024 11:46
@pires pires merged commit 2df67b4 into pires:main Oct 8, 2024
4 of 5 checks passed
pConn := &Conn{
bufReader: bufio.NewReader(conn),
bufReader: br,
reader: io.MultiReader(br, conn),

Choose a reason for hiding this comment

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

I got the idea but this does not look right: io.MultiReader will read br reader until EOF but it is a buffered reader that will read until connection returns EOF.

Choose a reason for hiding this comment

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

I think it should be something like #119

AlexanderYastrebov added a commit to AlexanderYastrebov/go-proxyproto that referenced this pull request Oct 10, 2024
Reverts and re-implemnets incorrect pires#116
which passed all connection data through the buffered reader.
AlexanderYastrebov added a commit to AlexanderYastrebov/go-proxyproto that referenced this pull request Oct 10, 2024
Reverts and re-implements incorrect pires#116
which passed all connection data through the buffered reader.
AlexanderYastrebov added a commit to AlexanderYastrebov/go-proxyproto that referenced this pull request Oct 10, 2024
Reverts and re-implements incorrect pires#116
which passed all connection data through the buffered reader.
AlexanderYastrebov added a commit to AlexanderYastrebov/go-proxyproto that referenced this pull request Oct 13, 2024
Reverts and re-implements incorrect pires#116
which passed all connection data through the buffered reader.
@mmatczuk
Copy link
Contributor Author

@AlexanderYastrebov is correct and there is a bug that causes the io.MultiReader always read from the buffered reader.

I think it would be better to instantiate the buffer in readHeader().
Only if buffer is not empty assign reader to multi reader that contains reader for the buffered bytes and the connection.

Taking a wider perspective I think that it would be better to have the parsing APIs based on io.Reader and use ReadAll instead of Peek(). This is out of scope of this pr.

mmatczuk added a commit to mmatczuk/go-proxyproto that referenced this pull request Oct 15, 2024
Fix bug introduced in pires#116 where io.MultiReader only reads from buffered reader.

Move buffer reader management to readHeader().
Remove Conn.bufReader, and make Conn.reader nil until readHeader() is called.
@AlexanderYastrebov
Copy link

Taking a wider perspective I think that it would be better to have the parsing APIs based on io.Reader and use ReadAll instead of Peek(). This is out of scope of this pr.

Yes, but then again one needs to keep a copy of read bytes in case there is no PROXY header to support #106 usecase.

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

Successfully merging this pull request may close these issues.

4 participants