summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Nagy <ronagy@icloud.com>2019-08-30 12:13:58 +0200
committerMatteo Collina <hello@matteocollina.com>2019-09-02 16:31:33 +0200
commit897587c0132da5b50f54409422b91a935739edb9 (patch)
tree97e16c07e561d9dd3ce3a42d6dd7fe02ae47f48a /lib
parent94c944d0d57062401dd11eb108e7717b9dac62d2 (diff)
downloadandroid-node-v8-897587c0132da5b50f54409422b91a935739edb9.tar.gz
android-node-v8-897587c0132da5b50f54409422b91a935739edb9.tar.bz2
android-node-v8-897587c0132da5b50f54409422b91a935739edb9.zip
stream: don't deadlock on aborted stream
Not all streams (e.g. http.ClientRequest) will always emit 'close' after 'aborted'. PR-URL: https://github.com/nodejs/node/pull/29376 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/streams/end-of-stream.js6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/internal/streams/end-of-stream.js b/lib/internal/streams/end-of-stream.js
index 850e5d3796..3f1c0f316c 100644
--- a/lib/internal/streams/end-of-stream.js
+++ b/lib/internal/streams/end-of-stream.js
@@ -82,12 +82,18 @@ function eos(stream, opts, callback) {
stream.on('close', onlegacyfinish);
}
+ // Not all streams will emit 'close' after 'aborted'.
+ if (typeof stream.aborted === 'boolean') {
+ stream.on('aborted', onclose);
+ }
+
stream.on('end', onend);
stream.on('finish', onfinish);
if (opts.error !== false) stream.on('error', onerror);
stream.on('close', onclose);
return function() {
+ stream.removeListener('aborted', onclose);
stream.removeListener('complete', onfinish);
stream.removeListener('abort', onclose);
stream.removeListener('request', onrequest);