fix(mesh): queue RPC sends per socket so one drain releases one frame (#41) #156

Merged
chrnx merged 1 commits from fix/mesh-rpc-send-order into develop 2026-10-24 19:32:23 +00:00
Owner

#152 made each mesh RPC send wait for drained(), but each one waited on
its own. A drain on a backed-up socket releases every waiter at once
(nodeSocket keeps them in one list), so they all sent and the buffer
overshot the 1 MiB mark by one frame per concurrent RPC: bounded, but not
what #152 claims. Found in the second pre-freeze review.

sendWhenDrained (ws-core, internal) chains sends per socket, and each
one waits for drained() when its turn comes. The buffer then peaks at
the mark plus one frame, however many RPCs wait, and frames go out in
call order. The teapot's reply and the link's sendRpc both use it.
The frame is built at send time, so a call that timed out while queued
sends nothing, and nothing is sent after the close.

Tests: a burst of five 100-byte frames behind a backed-up socket sends
one frame per drain, in order, with the buffer at most one frame. It
fails when each sender waits on its own. Also: a withdrawn frame is
skipped, and a frame queued at close is dropped.

#152 made each mesh RPC send wait for `drained()`, but each one waited on its own. A drain on a backed-up socket releases every waiter at once (`nodeSocket` keeps them in one list), so they all sent and the buffer overshot the 1 MiB mark by one frame per concurrent RPC: bounded, but not what #152 claims. Found in the second pre-freeze review. `sendWhenDrained` (ws-core, internal) chains sends per socket, and each one waits for `drained()` when its turn comes. The buffer then peaks at the mark plus one frame, however many RPCs wait, and frames go out in call order. The teapot's `reply` and the link's `sendRpc` both use it. The frame is built at send time, so a call that timed out while queued sends nothing, and nothing is sent after the close. Tests: a burst of five 100-byte frames behind a backed-up socket sends one frame per drain, in order, with the buffer at most one frame. It fails when each sender waits on its own. Also: a withdrawn frame is skipped, and a frame queued at close is dropped.
chrnx added 1 commit 2026-10-24 19:26:54 +00:00
fix(mesh): queue RPC sends per socket so one drain releases one frame (#41)
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / build (pull_request) Successful in 29s
CI / runtimes (edge) (pull_request) Successful in 19s
CI / runtimes (deno) (pull_request) Successful in 33s
1ae4c6f865
#152 made each mesh RPC send wait for `drained()`, but each one waited on
its own. A drain on a backed-up socket releases every waiter at once
(`nodeSocket` keeps them in one list), so they all sent and the buffer
overshot the 1 MiB mark by one frame per concurrent RPC: bounded, but not
what #152 claims. Found in the second pre-freeze review.

`sendWhenDrained` (ws-core, internal) chains sends per socket, and each
one waits for `drained()` when its turn comes. The buffer then peaks at
the mark plus one frame, however many RPCs wait, and frames go out in
call order. The teapot's `reply` and the link's `sendRpc` both use it.
The frame is built at send time, so a call that timed out while queued
sends nothing, and nothing is sent after the close.

Tests: a burst of five 100-byte frames behind a backed-up socket sends
one frame per drain, in order, with the buffer at most one frame. It
fails when each sender waits on its own. Also: a withdrawn frame is
skipped, and a frame queued at close is dropped.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
chrnx merged commit 19d6db7064 into develop 2026-10-24 19:32:23 +00:00
Sign in to join this conversation.