From 420fef27fbc192952c02bdbe50654553a1249408 Mon Sep 17 00:00:00 2001 From: dauletamirkhanov Date: Tue, 22 Jun 2021 19:20:29 +0600 Subject: [PATCH] first version createAsyncIterator should throw ERR_STREAM_PREMATURE_CLOSE if 'close' is emitted before 'end' --- lib/internal/streams/readable.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/internal/streams/readable.js b/lib/internal/streams/readable.js index 7f6876599cc7fc..752ab76f3cc233 100644 --- a/lib/internal/streams/readable.js +++ b/lib/internal/streams/readable.js @@ -60,7 +60,8 @@ const { ERR_INVALID_ARG_TYPE, ERR_STREAM_PUSH_AFTER_EOF, ERR_METHOD_NOT_IMPLEMENTED, - ERR_STREAM_UNSHIFT_AFTER_END_EVENT + ERR_STREAM_UNSHIFT_AFTER_END_EVENT, + ERR_STREAM_PREMATURE_CLOSE } = require('internal/errors').codes; const { validateObject } = require('internal/validators'); @@ -1123,6 +1124,10 @@ async function* createAsyncIterator(stream, options) { next.call(this); }) .on('close', function() { + if (endEmitted) { + throw new ERR_STREAM_PREMATURE_CLOSE(); + } + closeEmitted = true; next.call(this); });