-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
Closed
Labels
streamIssues and PRs related to the stream subsystem.Issues and PRs related to the stream subsystem.
Description
- Version: v11.9.0
- Platform: macOS
- Subsystem: stream
The 'error' event can be emitted multiple times when using writable.destroy() if the _destroy() callback is called asynchronously. Here is a test case:
const { Writable } = require('stream');
const writable = new Writable({
destroy(err, callback) {
process.nextTick(callback, new Error('oops'));
}
});
writable.on('error', console.error);
writable.destroy();
// Assume an internal resource is closed in the `_destroy()` implementation.
// The resource fails to be closed cleanly causing `writable.destroy()` to be
// called again with an error.
writable.destroy(new Error('error'));Actual result:
The 'error' event is emitted twice.
Expected result:
The 'error' event is emitted only once.
This is because the _writableState.errorEmitted guard is set to true when the callback is called.
mcollina
Metadata
Metadata
Assignees
Labels
streamIssues and PRs related to the stream subsystem.Issues and PRs related to the stream subsystem.