Skip to content

Commit fae9b8b

Browse files
Avoid handling ping after close frame has been sent
1 parent 14fb98e commit fae9b8b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

read.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package websocket
@@ -265,6 +266,13 @@ func (c *Conn) handleControl(ctx context.Context, h header) (err error) {
265266

266267
switch h.opcode {
267268
case opPing:
269+
c.closeMu.Lock()
270+
wroteClose := c.wroteClose
271+
c.closeMu.Unlock()
272+
if wroteClose {
273+
// Cannot respond to ping with a pong because we already sent a close frame.
274+
return nil
275+
}
268276
return c.writeControl(ctx, opPong, b)
269277
case opPong:
270278
c.activePingsMu.Lock()

0 commit comments

Comments
 (0)