Skip to content

Commit

Permalink
read.go: Avoid handling ping after close frame has been sent
Browse files Browse the repository at this point in the history
Closes nhooyr#298
  • Loading branch information
bhallionOhbibi authored and nhooyr committed Oct 19, 2023
1 parent c537145 commit 69f55f3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions read.go
Expand Up @@ -286,6 +286,13 @@ func (c *Conn) handleControl(ctx context.Context, h header) (err error) {

switch h.opcode {
case opPing:
c.closeMu.Lock()
wroteClose := c.wroteClose
c.closeMu.Unlock()
if wroteClose {
// Cannot respond to ping with a pong because we already sent a close frame.
return nil
}
return c.writeControl(ctx, opPong, b)
case opPong:
c.activePingsMu.Lock()
Expand Down

0 comments on commit 69f55f3

Please sign in to comment.