Skip to content

Commit

Permalink
Document bug with release of bufio read/writers for client
Browse files Browse the repository at this point in the history
  • Loading branch information
nhooyr committed May 30, 2019
1 parent b39ca87 commit 510eed5
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"bytes"
"context"
"encoding/base64"
"golang.org/x/xerrors"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
"sync"

"golang.org/x/xerrors"
)

// DialOptions represents the options available to pass to Dial.
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190429184909-35c670923e21 h1:Kjcw+D2LTzLmxOHrMK9uvYP/NigJ0EdwMgzt6EU+Ghs=
golang.org/x/tools v0.0.0-20190429184909-35c670923e21/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/xerrors v0.0.0-20190315151331-d61658bd2e18 h1:1AGvnywFL1aB5KLRxyLseWJI6aSYPo3oF7HSpXdWQdU=
golang.org/x/xerrors v0.0.0-20190315151331-d61658bd2e18/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522 h1:bhOzK9QyoD0ogCnFro1m2mz41+Ib0oOhfJnBp5MR4K4=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
mvdan.cc/sh v2.6.4+incompatible h1:eD6tDeh0pw+/TOTI1BBEryZ02rD2nMcFsgcvde7jffM=
Expand Down
1 change: 1 addition & 0 deletions websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (c *Conn) close(err error) {
if c.client {
go func() {
<-c.readLoopDone
// TODO this does not work if reader errors out.
c.readDataLock <- struct{}{}
c.writeFrameLock <- struct{}{}

Expand Down
2 changes: 1 addition & 1 deletion websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ func benchConn(b *testing.B, echo, stream bool, size int) {
b.Fatal(err)
}

_, err = r.Read(nil)
_, err = r.Read([]byte{0})
if !xerrors.Is(err, io.EOF) {
b.Fatalf("more data in reader than needed")
}
Expand Down
5 changes: 3 additions & 2 deletions wsjson/wsjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ package wsjson
import (
"context"
"encoding/json"
"golang.org/x/xerrors"
"io"

"golang.org/x/xerrors"

"nhooyr.io/websocket"
)

Expand Down Expand Up @@ -46,7 +47,7 @@ func read(ctx context.Context, c *websocket.Conn, v interface{}) error {
// we support concurrent reading.
// So the Reader has to synchronize with Read somehow.
// Maybe its best to bring back the old readLoop?
_, err = r.Read(nil)
_, err = r.Read([]byte{0})
if !xerrors.Is(err, io.EOF) {
return xerrors.Errorf("more data than needed in reader")
}
Expand Down

0 comments on commit 510eed5

Please sign in to comment.