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: small reads should not fail #1145

Closed
gopherbot opened this issue Sep 27, 2010 · 3 comments
Closed

x/net/websocket: small reads should not fail #1145

gopherbot opened this issue Sep 27, 2010 · 3 comments
Milestone

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 27, 2010

by joamaki:

Websocket's Read() method returns os.E2BIG if the message doesn't fit
the buffer. The JSON decoder doesn't handle this and returns the error
to the caller.

I'm currently working around this with:

--- a/src/pkg/json/stream.go    Mon Sep 27 11:42:58 2010 +1000
+++ b/src/pkg/json/stream.go    Mon Sep 27 10:25:10 2010 +0300
@@ -107,7 +107,17 @@
 
        // Read.  Delay error for next iteration (after scan).
        var n int
-       n, err = dec.r.Read(dec.buf[len(dec.buf):cap(dec.buf)])
+       for {
+           n, err = dec.r.Read(dec.buf[len(dec.buf):cap(dec.buf)])
+           if err == os.E2BIG {
+               newBuf := make([]byte, len(dec.buf), 2*cap(dec.buf)+minRead)
+               copy(newBuf, dec.buf)
+               dec.buf = newBuf
+               continue
+           }
+           break
+       }
+
        dec.buf = dec.buf[0 : len(dec.buf)+n]
    }
    return scanp, nil
@rsc
Copy link
Contributor

@rsc rsc commented Sep 27, 2010

Comment 1:

The bug is that websocket's Read should be able to handle
reading a fragment of a frame.  It should remember that
there is more data coming and return that data to the next Read.

Status changed to Accepted.

@rsc
Copy link
Contributor

@rsc rsc commented Sep 27, 2010

Comment 3:

ukai was not a typo; he wrote the websocket package
@rsc
Copy link
Contributor

@rsc rsc commented Oct 21, 2010

Comment 4:

This issue was closed by revision 64cc5be.

Status changed to Fixed.

@mikioh mikioh changed the title websocket: small reads should not fail x/net/websocket: small reads should not fail Jul 30, 2015
@mikioh mikioh modified the milestone: Unreleased Jul 30, 2015
@golang golang locked and limited conversation to collaborators Aug 5, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.