Skip to content

Commit 298dea0

Browse files
authored
stream: relocate the status checking code in the onwritecomplete
relocate the status checking code before verifying if the stream is destroyed PR-URL: #54032 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 294ae14 commit 298dea0

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

lib/internal/stream_base_commons.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,18 @@ function onWriteComplete(status) {
8383

8484
const stream = this.handle[owner_symbol];
8585

86-
if (stream.destroyed) {
87-
if (typeof this.callback === 'function')
88-
this.callback(null);
89-
return;
86+
if (status < 0) {
87+
const error = new ErrnoException(status, 'write', this.error);
88+
if (typeof this.callback === 'function') {
89+
return this.callback(error);
90+
}
91+
92+
return stream.destroy(error);
9093
}
9194

92-
// TODO (ronag): This should be moved before if(stream.destroyed)
93-
// in order to avoid swallowing error.
94-
if (status < 0) {
95-
const ex = new ErrnoException(status, 'write', this.error);
95+
if (stream.destroyed) {
9696
if (typeof this.callback === 'function')
97-
this.callback(ex);
98-
else
99-
stream.destroy(ex);
97+
this.callback(null);
10098
return;
10199
}
102100

0 commit comments

Comments
 (0)