From b78ed7706df03902db09f832ab2bc2943e4e9960 Mon Sep 17 00:00:00 2001 From: James Coglan Date: Sat, 14 Mar 2015 10:03:26 +0000 Subject: [PATCH] Don't send a close frame in response to receiving one, if we already sent a close frame. --- lib/websocket/driver/hybi.rb | 2 +- spec/websocket/driver/hybi_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/websocket/driver/hybi.rb b/lib/websocket/driver/hybi.rb index 6e30bad..738be55 100644 --- a/lib/websocket/driver/hybi.rb +++ b/lib/websocket/driver/hybi.rb @@ -246,7 +246,7 @@ module WebSocket end def shutdown(code, reason) - frame(reason, :close, code) + frame(reason, :close, code) if @ready_state < 2 @frame = @message = nil @ready_state = 3 @stage = 5 diff --git a/spec/websocket/driver/hybi_spec.rb b/spec/websocket/driver/hybi_spec.rb index 9200268..c13f874 100644 --- a/spec/websocket/driver/hybi_spec.rb +++ b/spec/websocket/driver/hybi_spec.rb @@ -457,6 +457,11 @@ describe WebSocket::Driver::Hybi do it "changes the state to :closed" do expect(driver.state).to eq :closed end + + it "does not write another close frame" do + expect(socket).not_to receive(:write) + driver.parse [0x88, 0x04, 0x03, 0xe9, 0x4f, 0x4b].pack("C*") + end end end