Skip to content

Use readatleast instead of reimplementing it #252

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

Closed
wants to merge 2 commits into from
Closed

Use readatleast instead of reimplementing it #252

wants to merge 2 commits into from

Conversation

nightlyone
Copy link

use io.ReadAtLeast instead of reimplementing it

This also returns the correct error (io.UnexpectedEOF), if we didn't get what we want.

It made no difference to the callers -- which I audited down to packets.go -- where we convert any error from this path to driver.ErrBadConn so the propagation of this new error stops in packets.go.

Future enhancements can now differentiate between the EOF situation after we got what we want and before we could read a complete packet.

This also returns the correct error (io.UnexpectedEOF),
if we didn't get what we want.
@julienschmidt
Copy link
Member

Thank you for the proposal, but except for returning the right error this doesn't improve anything.

I think the following lines in io.ReadAtLeast can actually cause problems. We had problems with masked errors in the buffer code before:

if n >= min {
    err = nil
}

Moreover io.ReadAtLeast is not as optimized as our own reimplementation can be. Since these are are just a few lines of code, I think it is OK to reimplement it.

Future enhancements can now differentiate between the EOF situation after we got what we want and before we could read a complete packet.

No, there is no case where an expected EOF can happen. But you are right, the current code returns the wrong error, I therefore propose #269 which fixes the error and introduces some further optimizations instead.

@nightlyone
Copy link
Author

I agree with the theoretically masked error issue. Maybe worth filing an issue at Go itself?

The history of this file shows, that re-implementing buffering is error prone. Errors in buffering code have a history of lots of bugs in many software, so I personally wouldn't do it.

On the other hand buffering code is a highly opinionated and fun field of play :-)

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.

2 participants