diff --git a/read.go b/read.go index 6d0e9aa9..d7facb31 100644 --- a/read.go +++ b/read.go @@ -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()