From e264d6ab51a0f537caca4c635aaee1dc8bce5ca2 Mon Sep 17 00:00:00 2001 From: David Hogan Date: Wed, 10 Jan 2024 10:11:44 +1100 Subject: [PATCH] Only send pong if OPEN. --- src/websockets/protocol.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/websockets/protocol.py b/src/websockets/protocol.py index 765e6b9b..c2260ed9 100644 --- a/src/websockets/protocol.py +++ b/src/websockets/protocol.py @@ -630,8 +630,9 @@ def recv_frame(self, frame: Frame) -> None: elif frame.opcode is OP_PING: # 5.5.2. Ping: "Upon receipt of a Ping frame, an endpoint MUST # send a Pong frame in response" - pong_frame = Frame(OP_PONG, frame.data) - self.send_frame(pong_frame) + if self.state is OPEN: + pong_frame = Frame(OP_PONG, frame.data) + self.send_frame(pong_frame) elif frame.opcode is OP_PONG: # 5.5.3 Pong: "A response to an unsolicited Pong frame is not