Skip to content

Commit 4b84d25

Browse files
committed
Fix a race with c.closed
1 parent 999b812 commit 4b84d25

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

conn_notjs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ func (c *Conn) close(err error) {
127127
if c.isClosed() {
128128
return
129129
}
130+
c.setCloseErrLocked(err)
130131
close(c.closed)
131132
runtime.SetFinalizer(c, nil)
132-
c.setCloseErrLocked(err)
133133

134134
// Have to close after c.closed is closed to ensure any goroutine that wakes up
135135
// from the connection being closed also sees that c.closed is closed and returns

conn_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestConn(t *testing.T) {
5555
defer c2.Close(websocket.StatusInternalError, "")
5656
defer c1.Close(websocket.StatusInternalError, "")
5757

58-
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
58+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
5959
defer cancel()
6060

6161
echoLoopErr := xsync.Go(func() error {
@@ -142,7 +142,7 @@ func TestConn(t *testing.T) {
142142
defer c1.Close(websocket.StatusInternalError, "")
143143
defer c2.Close(websocket.StatusInternalError, "")
144144

145-
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
145+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
146146
defer cancel()
147147

148148
c2.CloseRead(ctx)
@@ -242,7 +242,7 @@ func TestConn(t *testing.T) {
242242
defer c2.Close(websocket.StatusInternalError, "")
243243
defer c1.Close(websocket.StatusInternalError, "")
244244

245-
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
245+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
246246
defer cancel()
247247

248248
n1 := websocket.NetConn(ctx, c1, websocket.MessageBinary)
@@ -298,7 +298,7 @@ func TestConn(t *testing.T) {
298298
defer c2.Close(websocket.StatusInternalError, "")
299299
defer c1.Close(websocket.StatusInternalError, "")
300300

301-
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
301+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
302302
defer cancel()
303303

304304
n1 := websocket.NetConn(ctx, c1, websocket.MessageBinary)
@@ -333,7 +333,7 @@ func TestConn(t *testing.T) {
333333
defer c2.Close(websocket.StatusInternalError, "")
334334
defer c1.Close(websocket.StatusInternalError, "")
335335

336-
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
336+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
337337
defer cancel()
338338

339339
echoLoopErr := xsync.Go(func() error {
@@ -381,7 +381,7 @@ func TestConn(t *testing.T) {
381381
defer c2.Close(websocket.StatusInternalError, "")
382382
defer c1.Close(websocket.StatusInternalError, "")
383383

384-
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
384+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
385385
defer cancel()
386386

387387
echoLoopErr := xsync.Go(func() error {

0 commit comments

Comments
 (0)