Skip to content

fix: deliver frames split across reads in WebSocket active once mode - #1040

Open
Fudoshiki wants to merge 1 commit into
benoitc:masterfrom
Youimmi:ws-active-once-partial-frames
Open

Fudoshiki wants to merge 1 commit into
benoitc:masterfrom
Youimmi:ws-active-once-partial-frames

Conversation

@Fudoshiki

Copy link
Copy Markdown

What

In {active, once} mode, hackney_ws switches the socket to passive after the first TCP read, even when that read held only part of a frame. The partial frame is buffered but never delivered, and the connection stalls: the owner has received no message, so it has no reason to call ws_setopts/2 again. With this change, a read that completes no frame re-arms the socket with {active, once}, and reading continues until a whole frame can be delivered.

Why

A frame larger than one TCP read (for example a 1 MiB binary message, or any message spanning several TLS records) cannot be received in {active, once} mode, which is the mode that gives a client backpressure.

How to test

rebar3 eunit --module=hackney_ws_tests runs the new "Active mode once with a frame split across reads" test, which asks the mock server for a 1 MiB frame in {active, once} mode. It fails without the change and passes with it. The full rebar3 eunit suite (1,382 tests) passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant