Websocket incoming frame parsing fixes - #473
Conversation
|
How do you folks feel about the state machine parser? Is the robustness worth the performance cost, or should we instead try buffering the header (spends more RAM and/or we're playing I don't have a good way to quantify the performance either, all of our benchmarks so far have focused on outgoing frames. |
That's a tricky question! I think we could test that with websocat. |
Use a state machine to process headers byte-by-byte so we can handle partial reception at any point.
9ba38e6 to
7e0ee46
Compare
|
I'm working on some test cases for the fixes. Claude and I have found that the last fix (close reason handling) isn't really sufficient - we will have to defragment control frames for standards compliant operation. Stand by for more code. |
If a control frame spans multiple TCP packets, buffer the data so that the frame can be processed once fully received. This ensures that the frame can be correctly handled instead of generating invalid PONG responses or overrunning the buffer with a disconnect reason.
7e0ee46 to
6cca924
Compare
|
I read recently that modern AI is really, really good at finding all the bugs you ask it for. This is definitely turning out to be my experience here! I'm trying to validate the close-on-error semantics and it's turning in to a rabbit hole. There's a pernicious corner case with ... and there's more: in most cases where we close as a result of the client asking (like AsyncWebSocket), we must ack the bytes read before closing. Otherwise the TCP stack generates a RST-close instead of a FIN-close, as is required by the TCP protocol, to indicate that the remote client did not in fact consume all bytes. Even if it was safe to call I'm going to think about this one a bit -- wanted to share where it's at, though. |
Fix handling of incoming frame headers that span multiple packets, a corner case processing very large frames, and an edge case handling disconnect frames that are split between packets.
Filed as draft for these open concerns: