From 69f55f34aacbc9979a6c4b88190f3d7e6b7fa968 Mon Sep 17 00:00:00 2001 From: Benjamin Hallion Date: Thu, 25 May 2023 12:34:29 +0200 Subject: [PATCH] read.go: Avoid handling ping after close frame has been sent Closes #298 --- read.go | 7 +++++++ 1 file changed, 7 insertions(+) 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()