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