summaryrefslogtreecommitdiff
path: root/lib/_stream_writable.js
diff options
context:
space:
mode:
authorRobert Nagy <ronagy@icloud.com>2020-03-07 23:28:09 +0100
committerRobert Nagy <ronagy@icloud.com>2020-03-25 15:20:22 +0100
commit388cef61e8a4859b7505f7b5cf988eba27ce17b4 (patch)
treef59bbd98c1bb9f1c67f1ff95df616d3a2d674d05 /lib/_stream_writable.js
parent05f1df520064475a255d8956f9e1b6f4bf4c8543 (diff)
downloadnode-new-388cef61e8a4859b7505f7b5cf988eba27ce17b4.tar.gz
stream: align stream.Duplex with net.Socket
stream.Duplex and net.Socket slightly differs in behavior. Especially when it comes to the case where one side never becomes readable or writable. This aligns Duplex with the behavior of Socket. PR-URL: https://github.com/nodejs/node/pull/32139 Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/_stream_writable.js')
-rw-r--r--lib/_stream_writable.js10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js
index b24192101c..c3a7a35d2b 100644
--- a/lib/_stream_writable.js
+++ b/lib/_stream_writable.js
@@ -675,7 +675,13 @@ function finish(stream, state) {
// In case of duplex streams we need a way to detect
// if the readable side is ready for autoDestroy as well
const rState = stream._readableState;
- if (!rState || (rState.autoDestroy && rState.endEmitted)) {
+ const autoDestroy = !rState || (
+ rState.autoDestroy &&
+ // We don't expect the readable to ever 'end'
+ // if readable is explicitly set to false.
+ (rState.endEmitted || rState.readable === false)
+ );
+ if (autoDestroy) {
stream.destroy();
}
}
@@ -748,7 +754,7 @@ ObjectDefineProperties(Writable.prototype, {
// Compat. The user might manually disable writable side through
// deprecated setter.
return !!w && w.writable !== false && !w.destroyed && !w.errored &&
- !w.ending;
+ !w.ending && !w.ended;
},
set(val) {
// Backwards compatible.