stream: relocate the status checking code in the onwritecomplete

relocate the status checking code before verifying if the stream is
destroyed

PR-URL: https://github.com/nodejs/node/pull/54032
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
YoonSoo_Shin 2024-09-02 16:29:17 +09:00 committed by GitHub
parent 294ae14b98
commit 298dea0c63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -83,23 +83,21 @@ function onWriteComplete(status) {
const stream = this.handle[owner_symbol];
if (status < 0) {
const error = new ErrnoException(status, 'write', this.error);
if (typeof this.callback === 'function') {
return this.callback(error);
}
return stream.destroy(error);
}
if (stream.destroyed) {
if (typeof this.callback === 'function')
this.callback(null);
return;
}
// TODO (ronag): This should be moved before if(stream.destroyed)
// in order to avoid swallowing error.
if (status < 0) {
const ex = new ErrnoException(status, 'write', this.error);
if (typeof this.callback === 'function')
this.callback(ex);
else
stream.destroy(ex);
return;
}
stream[kUpdateTimer]();
stream[kAfterAsyncWrite](this);