Skip to content

Commit 28c6709

Browse files
committed
conn_test.go: Fix TestConcurrentClosePing
Closes #298 Closes #394 The close frame was being received from the peer before we were able to reset our write timeout and so we thought the write kept failing but it never was... Thanks @univerio and @bhallionOhbibi
1 parent e4879ab commit 28c6709

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Diff for: read.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ func (c *Conn) Read(ctx context.Context) (MessageType, []byte, error) {
6262
func (c *Conn) CloseRead(ctx context.Context) context.Context {
6363
ctx, cancel := context.WithCancel(ctx)
6464
go func() {
65+
defer c.CloseNow()
6566
defer cancel()
66-
c.Reader(ctx)
67-
c.Close(StatusPolicyViolation, "unexpected data message")
67+
_, _, err := c.Reader(ctx)
68+
if err == nil {
69+
c.Close(StatusPolicyViolation, "unexpected data message")
70+
}
6871
}()
6972
return ctx
7073
}

Diff for: write.go

+3
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ func (c *Conn) writeFrame(ctx context.Context, fin bool, flate bool, opcode opco
323323

324324
select {
325325
case <-c.closed:
326+
if opcode == opClose {
327+
return n, nil
328+
}
326329
return n, errClosed
327330
case c.writeTimeout <- context.Background():
328331
}

0 commit comments

Comments
 (0)