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

x/net/websocket: Read() doesn't read the whole frame #27967

Open
antong opened this issue Oct 2, 2018 · 3 comments
Open

x/net/websocket: Read() doesn't read the whole frame #27967

antong opened this issue Oct 2, 2018 · 3 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@antong
Copy link
Contributor

antong commented Oct 2, 2018

The documentation for websocket.(*Conn).Read() states:

func (ws *Conn) Read(msg []byte) (n int, err error)

Read implements the io.Reader interface: it reads data of a frame from the WebSocket connection.
if msg is not large enough for the frame data, it fills the msg and next Read will read the rest of the
frame data. it reads Text frame or Binary frame.

I interpret this as meaning that if msg is large enough, then the whole frame will be read (exceptio probat regulam in casibus non exceptis, the exception proves the rule).

However, in case of large frames (larger than bufio defaultBufSize) the read will always be short. Either the documentation or the implementation is wrong.

websocket.Message.Receive() does read the whole frame.

What version of Go are you using (go version)?

go1.11

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

Reproduced on:

  • GOOS=windows GOARCH=amd64
  • GOOS=linux GOARCH=amd64

What did you do?

I connected an x/net/websocket client and server, and had the server write a 5000 byte long frame using websocket.(*Conn).Write() and the client read it using websocket.(*Conn).Read().

Client: https://play.golang.org/p/BYtr4kSJUfu
Server: https://play.golang.org/p/LHWv9YfqsjB

What did you expect to see?

I expected websocket.(*Conn).Read() to read the whole 5000 byte long frame.

What did you see instead?

websocket.(*Conn).Read() read only 4092 bytes of the 5000 byte long frame.

@gopherbot gopherbot added this to the Unreleased milestone Oct 2, 2018
@gopherbot
Copy link

Change https://golang.org/cl/154137 mentions this issue: websocket: make Read reads the entire frame if the provided slice is large enough

@gopherbot
Copy link

Change https://golang.org/cl/162378 mentions this issue: websocket: read entire frame if provided slice is large enough

@antong
Copy link
Contributor Author

antong commented Sep 7, 2019

I think this actually is the same as #2134.

@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants