fix(async): don't crash streaming pushes on pooled Node Buffers (#278) - #292
Open
maximilliangrand wants to merge 1 commit into
Open
maximilliangrand wants to merge 1 commit into
maximilliangrand wants to merge 1 commit into
Conversation
…rrowz#278) The 101arrowz#227 fix filtered untransferable buffers only on the worker's first message. Streaming pushes (AsyncDeflate/AsyncZipDeflate/etc.) call the worker's postMessage directly, so pushing a Node Buffer -- whose backing ArrayBuffer is the shared, untransferable pool -- still threw `DataCloneError: Cannot transfer object of unsupported type`. Wrap the worker's postMessage so the transfer list is filtered on every message; untransferable buffers fall back to a structured clone. Adds an async regression test covering AsyncZipDeflate and AsyncDeflate.
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.
Fixes #278.
Repro (Node):
Cause: The async streaming classes transfer
d.bufferon every push. A NodeBuffer(fromBuffer.from/readFileSync) is a view into the shared poolArrayBufferthat Node marks untransferable, so the transfer throws. #227 (4b7a6cb) already filters untransferable buffers, but only on the worker's first message; streaming pushes callpostMessagedirectly and bypass it.Fix: Wrap the node worker's
postMessageso the transfer list is filtered on every message; untransferable buffers fall back to a structured clone (the same graceful degradation already used for cross-realm buffers). Fresh, transferableUint8Arrays still transfer as before.Tests/types/docs: adds an async regression test (
test/5-async.ts, previously empty) coveringAsyncZipDeflateandAsyncDeflatewith a pooled Buffer;tscclean; no public API or doc change.