fix: node 16 passthrough multiple callback error #88
+152
−126
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.
Node 16 includes a behavior change that breaks many stream implementation functions if they use async/await syntax. Async functions implicitly return a Promise, and node's stream internals automatically call the underlying callback if the function's result is a thenable. There is some logic to skip the automatic callback if it was already called explicitly in the function; however, this can execute before other asynchronous tasks, which results in a
ERR_MULTIPLE_CALLBACK
error when the explicit callback is invoked. For example, the callback in thisdrain
event handler will often trigger the error:This new behavior for thenables is undocumented and has already been deprecated. Unfortunately, we need to live with it for now. The most straightforward solution is to use a Promise chain instead of async/await in NodeClam
passthrough()
'sTransform
implementation.This PR also makes a change to use
stream.Readable
in jsdoc instead ofReadableStream
from the experimental Web Streams API. (Complementary types change in DefinitelyTyped/DefinitelyTyped#58698.)Fixes #82
Refs nodejs/node#39535, nodejs/node#40773