diff --git a/lib/internal/stream_base_commons.js b/lib/internal/stream_base_commons.js index f6c3c5a8cf1..76a87ab74b7 100644 --- a/lib/internal/stream_base_commons.js +++ b/lib/internal/stream_base_commons.js @@ -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);