Skip to content

Commit

Permalink
conn_test.go: Fix TestConcurrentClosePing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nhooyr committed Oct 19, 2023
1 parent e4879ab commit 28c6709
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions read.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ func (c *Conn) Read(ctx context.Context) (MessageType, []byte, error) {
func (c *Conn) CloseRead(ctx context.Context) context.Context {
ctx, cancel := context.WithCancel(ctx)
go func() {
defer c.CloseNow()
defer cancel()
c.Reader(ctx)
c.Close(StatusPolicyViolation, "unexpected data message")
_, _, err := c.Reader(ctx)
if err == nil {
c.Close(StatusPolicyViolation, "unexpected data message")
}
}()
return ctx
}
Expand Down
3 changes: 3 additions & 0 deletions write.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ func (c *Conn) writeFrame(ctx context.Context, fin bool, flate bool, opcode opco

select {
case <-c.closed:
if opcode == opClose {
return n, nil
}
return n, errClosed
case c.writeTimeout <- context.Background():
}
Expand Down

0 comments on commit 28c6709

Please sign in to comment.