From 9379ebe47deb8bdb3e7042cf0268588b8358261f Mon Sep 17 00:00:00 2001 From: Naja Melan Date: Thu, 12 Sep 2019 22:16:45 +0200 Subject: [PATCH] Don't swallow ping/pong while waiting for close acknowledgement --- src/protocol/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 169b1ff..36a440d 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -383,13 +383,15 @@ impl WebSocketContext { OpCtl::Reserved(i) => Err(Error::Protocol( format!("Unknown control frame type {}", i).into(), )), - OpCtl::Ping | OpCtl::Pong if !self.state.is_active() => { - // No ping processing while closing. + OpCtl::Ping | OpCtl::Pong if !self.state.can_read() => { Ok(None) } OpCtl::Ping => { let data = frame.into_data(); - self.pong = Some(Frame::pong(data.clone())); + // No ping processing after we sent a close frame. + if self.state.is_active() { + self.pong = Some(Frame::pong(data.clone())); + } Ok(Some(Message::Ping(data))) } OpCtl::Pong => Ok(Some(Message::Pong(frame.into_data()))),