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

Avoid returning 0, nil in netConn.Read #367

Closed
MarcoPolo opened this issue Feb 7, 2023 · 4 comments
Closed

Avoid returning 0, nil in netConn.Read #367

MarcoPolo opened this issue Feb 7, 2023 · 4 comments
Milestone

Comments

@MarcoPolo
Copy link

When we reach the end of the frame we currently return 0, nil (https://github.com/nhooyr/websocket/blob/master/netconn.go#L118). The io.Reader docs discourage this:

Implementations of Read are discouraged from returning a zero byte count with a nil error, except when len(p) == 0.

This seems to have confused other folks as well: #353

My recommendation is we don't return 0, nil and instead block until we get data or a proper error.

@nhooyr
Copy link
Owner

nhooyr commented Feb 7, 2023

Will change because the docs for io.Reader discourage it but if your code is using io.Reader correctly this should never be a problem.

@MarcoPolo
Copy link
Author

How do you think you want to solve it? Loop until error or data? Or something else?

I'm happy to submit a patch.

@nhooyr
Copy link
Owner

nhooyr commented Sep 28, 2023

Related golang/go#27531 (comment)

nhooyr added a commit that referenced this issue Oct 13, 2023
@nhooyr
Copy link
Owner

nhooyr commented Oct 13, 2023

Fixed in dev.

@nhooyr nhooyr closed this as completed Oct 13, 2023
nhooyr added a commit that referenced this issue Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants