tungstenite-rs icon indicating copy to clipboard operation
tungstenite-rs copied to clipboard

Socket should flush before closing

Open TroyKomodo opened this issue 5 months ago • 1 comments

I noticed some strange behavior in the way closes are handled when we are the server and a client initiates a close.

The server responds with a close frame, however this close frame is not sent unless we call flush one more time on the socket. I think it should be the library's responsibility to flush the socket when a close frame is sent internally by the library.

No flush call

2024-01-31T18:20:16.082142Z TRACE tungstenite::protocol::frame::frame: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/frame/frame.rs:144: Parsed headers [136, 130]    
2024-01-31T18:20:16.082154Z TRACE tungstenite::protocol::frame::frame: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/frame/frame.rs:148: First: 10001000    
2024-01-31T18:20:16.082162Z TRACE tungstenite::protocol::frame::frame: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/frame/frame.rs:149: Second: 10000010    
2024-01-31T18:20:16.082172Z TRACE tungstenite::protocol::frame::frame: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/frame/frame.rs:158: Opcode: Control(Close)    
2024-01-31T18:20:16.082182Z TRACE tungstenite::protocol::frame::frame: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/frame/frame.rs:161: Masked: true    
2024-01-31T18:20:16.082192Z TRACE tungstenite::protocol::frame: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/frame/mod.rs:200: received frame 
<FRAME>
final: true
reserved: false false false
opcode: CLOSE
length: 8
payload length: 2
payload: 0x5ce3
                
2024-01-31T18:20:16.082215Z DEBUG tungstenite::protocol: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/mod.rs:675: Received close frame: Some(CloseFrame { code: Normal, reason: "" })    
2024-01-31T18:20:16.082227Z DEBUG tungstenite::protocol: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/mod.rs:692: Replying to close with Frame { header: FrameHeader { is_final: true, rsv1: false, rsv2: false, rsv3: false, opcode: Control(Close), mask: None }, payload: [3, 232] }    
2024-01-31T18:20:16.082239Z TRACE tungstenite::protocol: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/mod.rs:413: Received message     
image

Explicit flush call

2024-01-31T18:18:02.272064Z TRACE tungstenite::protocol::frame::frame: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/frame/frame.rs:144: Parsed headers [136, 130]    
2024-01-31T18:18:02.272073Z TRACE tungstenite::protocol::frame::frame: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/frame/frame.rs:148: First: 10001000    
2024-01-31T18:18:02.272081Z TRACE tungstenite::protocol::frame::frame: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/frame/frame.rs:149: Second: 10000010    
2024-01-31T18:18:02.272090Z TRACE tungstenite::protocol::frame::frame: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/frame/frame.rs:158: Opcode: Control(Close)    
2024-01-31T18:18:02.272100Z TRACE tungstenite::protocol::frame::frame: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/frame/frame.rs:161: Masked: true    
2024-01-31T18:18:02.272109Z TRACE tungstenite::protocol::frame: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/frame/mod.rs:200: received frame 
<FRAME>
final: true
reserved: false false false
opcode: CLOSE
length: 8
payload length: 2
payload: 0x9231
                
2024-01-31T18:18:02.272132Z DEBUG tungstenite::protocol: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/mod.rs:675: Received close frame: Some(CloseFrame { code: Normal, reason: "" })    
2024-01-31T18:18:02.272144Z DEBUG tungstenite::protocol: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/mod.rs:692: Replying to close with Frame { header: FrameHeader { is_final: true, rsv1: false, rsv2: false, rsv3: false, opcode: Control(Close), mask: None }, payload: [3, 232] }    
2024-01-31T18:18:02.272155Z TRACE tungstenite::protocol: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/mod.rs:413: Received message     
2024-01-31T18:18:02.272201Z TRACE tungstenite::protocol: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/mod.rs:494: Sending pong/close    
2024-01-31T18:18:02.272210Z TRACE tungstenite::protocol: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/mod.rs:724: Sending frame: Frame { header: FrameHeader { is_final: true, rsv1: false, rsv2: false, rsv3: false, opcode: Control(Close), mask: None }, payload: [3, 232] }    
2024-01-31T18:18:02.272220Z TRACE tungstenite::protocol::frame: /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.21.0/src/protocol/frame/mod.rs:219: writing frame 
<FRAME>
final: true
reserved: false false false
opcode: CLOSE
length: 4
payload length: 2
payload: 0x03e8
image

TroyKomodo avatar Jan 31 '24 18:01 TroyKomodo