- Version: master
- Platform: all
- Subsystem: stream
'use strict';const{ Readable }=require('stream');constr=newReadable({objectMode: true,read(){this.push('asdf');this.push('hehe');// note: no this.push(null);// also reproducible with setTimeout(() => { this.push(null); }, 1000); here.}});(async()=>{forawait(constaofr){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.
/cc @mcollina@devsnek
Refs: #23730#23785
Prints
It seems the
ERR_STREAM_PREMATURE_CLOSEis erroneous, as I would expect the loop to terminate without error. Replacingr.destroy(null)withr.destroy(new Error())would result in a rejected promise with the newly created error, as expected./cc @mcollina@devsnek
Refs: #23730#23785