fix(mesh): RPC frames wait for the send buffer too (CARD-26, #41)
CARD-26 made the WebSocket route pump await `drained()` before each pull, but mesh RPC traffic sends outside that pump, so it never waited: - teapot: `handleRpc` runs concurrently per rpc-req, so a teacup that keeps sending requests and stops reading grows the teapot's buffer by one response each. - link: `sendRpc` sent each rpc-req at once, whatever the buffer held. Both now wait for `drained()` before sending. The teapot drops a response whose socket closed while waiting. The link starts its timeout before waiting, so a teapot that stops reading still answers 504, and a call that settles while waiting (timeout or close) is never sent late. Found in the pre-freeze integrated review. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
4 files changed
+88
-4
No files matched your search
+5
-1
@@ -119,7 +119,11 @@ function sendRpc(
|
||||
}, timeoutMs);
|
||||
|
||||
pending.set(id, { name, resolve: resolveCall, reject: rejectCall, timer });
|
||||
socket.send(encode({ type: 'rpc-req', id, kind, name, ctx }));
|
||||
// Not before the socket has room (#41); the timeout already runs, so a teapot that stops
|
||||
// reading still answers 504. Settled while waiting (timeout, close): nothing left to send.
|
||||
void (socket.drained?.() ?? Promise.resolve()).then(() => {
|
||||
if (pending.has(id) && !socket.abort.aborted) socket.send(encode({ type: 'rpc-req', id, kind, name, ctx }));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user