diff options
author | Robert Nagy <ronagy@icloud.com> | 2019-08-17 14:11:37 +0300 |
---|---|---|
committer | Robert Nagy <ronagy@icloud.com> | 2020-04-03 20:00:28 +0300 |
commit | 8f86986985b161b7fb5aa41283d792417329bc2c (patch) | |
tree | 12c45e4ee30facb9fb17eb12b1daf58a2aec7e4f /lib/internal/stream_base_commons.js | |
parent | b9da063ae9034b3fd8207791ef78a5e769a5eb0d (diff) |
stream: use callback to properly propagate error
The stream will be destroyed upstream through the proper error
flow.
PR-URL: https://github.com/nodejs/node/pull/29179
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'lib/internal/stream_base_commons.js')
-rw-r--r-- | lib/internal/stream_base_commons.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/internal/stream_base_commons.js b/lib/internal/stream_base_commons.js index 2a31221f11d..0278e7240c3 100644 --- a/lib/internal/stream_base_commons.js +++ b/lib/internal/stream_base_commons.js @@ -88,9 +88,14 @@ function onWriteComplete(status) { return; } + // TODO (ronag): This should be moved before if(stream.destroyed) + // in order to avoid swallowing error. if (status < 0) { const ex = errnoException(status, 'write', this.error); - stream.destroy(ex, this.callback); + if (typeof this.callback === 'function') + this.callback(ex); + else + stream.destroy(ex); return; } @@ -134,7 +139,7 @@ function writevGeneric(self, data, cb) { // Retain chunks if (err === 0) req._chunks = chunks; - afterWriteDispatched(self, req, err, cb); + afterWriteDispatched(req, err, cb); return req; } @@ -142,16 +147,16 @@ function writeGeneric(self, data, encoding, cb) { const req = createWriteWrap(self[kHandle]); const err = handleWriteReq(req, data, encoding); - afterWriteDispatched(self, req, err, cb); + afterWriteDispatched(req, err, cb); return req; } -function afterWriteDispatched(self, req, err, cb) { +function afterWriteDispatched(req, err, cb) { req.bytes = streamBaseState[kBytesWritten]; req.async = !!streamBaseState[kLastWriteWasAsync]; if (err !== 0) - return self.destroy(errnoException(err, 'write', req.error), cb); + return cb(errnoException(err, 'write', req.error)); if (!req.async) { cb(); @@ -264,7 +269,6 @@ function setStreamTimeout(msecs, callback) { } module.exports = { - createWriteWrap, writevGeneric, writeGeneric, onStreamRead, |