[14.x] stream: fix regression on duplex end
Backport Decide the return status of writeOrBuffer before calling stream.write which can reset state.length
Refs: https://github.com/nodejs/node/pull/35941/ Fixes: https://github.com/nodejs/node/issues/35926
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines