feat: Stream backpressure and drain (#43) - #25692
Merged
Merged
Conversation
enochgroot
force-pushed
the
feat/stream-drain
branch
from
September 19, 2026 13:49
26912b4 to
be95199
Compare
- Queue packed messages when write() returns false - Re-emit drain; cap pending sends at 1024 - Drop the queue on underlying error/close/end - Version 3.3.0 Closes msgpack#43.
enochgroot
force-pushed
the
feat/stream-drain
branch
from
September 19, 2026 13:52
be95199 to
7f8b373
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stream.sendqueues packed messages when the underlying writable returnsfalse, then flushes FIFO ondrain.drainso callers can listen onmsgpack.Stream, not only on the raw socket.send()throws. Version 3.3.0.Motivation
Stream.sendreturned the boolean fromwrite()but did not listen fordrainand did not queue if the caller kept sending after backpressure. Slow sockets could drop messages.Closes #43
Changes
write()returns false; flush FIFO ondrain.send()stays synchronous and returns the boolean fromwrite(), orfalseif the message was queued.write(buf)without inventing an encoding; a supplied callback runs after that buffer is written or if the queue is dropped.send()throws a catchableErrormentioning backpressure / queue full.error/close/end, drop the queue and emiterrorif unsent messages remain. Handlers do not throw.data/msgpath is unchanged (packed0/null,bytes_remainingsnapshot, error-on-malformed).src/msgpack.ccchange.Stacked PR
Parent #40 is still open: #25691 (
feat/lazy-unpack@ 81bf44f). This branch is stacked on that. The diff vsmasterincludes those commits; Stream backpressure is the commit on top.Test Plan
npm test— 222/222)npm run coverage:js)writereturns true;sendreturns true; no queuewritereturns false; secondsendis queued and flushed FIFO ondrainsendthrowssendstill runs (immediate and queued)0andnullstill emit asmsg(no Stream: unpacking '0' doesn't trigger 'msg' emit #44 regression)src/msgpack.ccchange; worker_threads suite still greenNotes for Reviewers
feat/lazy-unpack, not the full stack vs master.