-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
Labels
streamIssues and PRs related to the stream subsystem.Issues and PRs related to the stream subsystem.
Description
- Version: master
- Platform: all
- Subsystem: stream
'use strict';
const { Readable } = require('stream');
const r = new Readable({
objectMode: true,
read() {
this.push('asdf');
this.push('hehe');
// note: no this.push(null);
// also reproducible with setTimeout(() => { this.push(null); }, 1000); here.
}
});
(async () => {
for await (const a of r) {
r.destroy(null);
}
console.log('done');
})();
Prints
(node:90745) ExperimentalWarning: Readable[Symbol.asyncIterator] is an experimental feature. This feature could change at any time
(node:90745) UnhandledPromiseRejectionWarning: Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
at Readable.onclose (internal/streams/end-of-stream.js:64:36)
at Readable.emit (events.js:182:13)
at emitCloseNT (internal/streams/destroy.js:59:8)
at internalTickCallback (internal/process/next_tick.js:72:19)
at process._tickCallback (internal/process/next_tick.js:47:5)
at Function.Module.runMain (internal/modules/cjs/loader.js:763:11)
at startup (internal/bootstrap/node.js:308:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:878:3)
(node:90745) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an asyncfunction without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:90745) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
It seems the ERR_STREAM_PREMATURE_CLOSE
is erroneous, as I would expect the loop to terminate without error. Replacing r.destroy(null)
with r.destroy(new Error())
would result in a rejected promise with the newly created error, as expected.
Metadata
Metadata
Assignees
Labels
streamIssues and PRs related to the stream subsystem.Issues and PRs related to the stream subsystem.