stream: improve Readable.from error handling#37158
stream: improve Readable.from error handling#37158benjamingr wants to merge 4 commits intonodejs:masterfrom
Conversation
| }; | ||
|
|
||
| async function close() { | ||
| async function close(error) { |
There was a problem hiding this comment.
This is tricky and I want feedback on the semantics, basically:
- If we had an error (
.destroy(err)) we call.throw- this aligns the behaviour of.fromwith other methods and means stuff likeaddAbortSignalautomagically "works". - If after calling
throwthe iterator did not finish - we also call.return
| if (done) { | ||
| readable.push(null); | ||
| } else if (readable.destroyed) { | ||
| await close(); |
There was a problem hiding this comment.
This check is no longer necessary without needToClose since _destroy is called and if the stream is destroyed the iterator is closed.
lib/internal/streams/from.js
Outdated
|
|
||
| async function close() { | ||
| async function close(error) { | ||
| const hadError = typeof error !== 'undefined'; |
There was a problem hiding this comment.
Wouldn't error be null?
node/lib/internal/streams/destroy.js
Line 67 in 683754c
3f712a5 to
0bce498
Compare
|
I've rebased and force pushed to solve to git conflicts introduced by my PR. |
|
@aduh95 very kind of you, thanks 🙇♂️ |
|
@mcollina I might be a bit overcautious* - but I prefer to err on the side of caution. What steps can I take to ensure there is less breakage here? Thoughts:
Anything else? (since the old behaviour was just an overlooked bug/edge-case and probably not relied on) |
|
Putting "blocked" so this doesn't land by accident in the meantime. |
|
I went through most CITGM failures and there don't seem to be new/related ones |
|
I do not think we have any modules using this in CITGM. It's not touching any old/critical APIs, so it should be good to land. |
|
Thanks matteo. Landed in 03380bc |
PR-URL: #37158 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
PR-URL: #37158 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Notable Changes: * crypto: * add keyObject.export() 'jwk' format option (Filip Skokan) #37081 * deps: * upgrade to libuv 1.41.0 (Colin Ihrig) #37360 * doc: * add dmabupt to collaborators (Xu Meng) #37377 * refactor fs docs structure (James M Snell) #37170 * fs: * add fsPromises.watch() (James M Snell) #37179 * use a default callback for fs.close() (James M Snell) #37174 * add AbortSignal support to watch (Benjamin Gruenbaum) #37190 * perf_hooks: * introduce createHistogram (James M Snell) #37155 * stream: * improve Readable.from error handling (Benjamin Gruenbaum) #37158 * timers: * introduce setInterval async iterator (linkgoron) #37153 * tls: * add ability to get cert/peer cert as X509Certificate object (James M Snell) #37070
Notable Changes: * crypto: * add keyObject.export() 'jwk' format option (Filip Skokan) #37081 * deps: * upgrade to libuv 1.41.0 (Colin Ihrig) #37360 * doc: * add dmabupt to collaborators (Xu Meng) #37377 * refactor fs docs structure (James M Snell) #37170 * fs: * add fsPromises.watch() (James M Snell) #37179 * use a default callback for fs.close() (James M Snell) #37174 * add AbortSignal support to watch (Benjamin Gruenbaum) #37190 * perf_hooks: * introduce createHistogram (James M Snell) #37155 * stream: * improve Readable.from error handling (Benjamin Gruenbaum) #37158 * timers: * introduce setInterval async iterator (linkgoron) #37153 * tls: * add ability to get cert/peer cert as X509Certificate object (James M Snell) #37070
Notable Changes: * crypto: * add keyObject.export() jwk format option (Filip Skokan) #37081 * deps: * upgrade to libuv 1.41.0 (Colin Ihrig) #37360 * doc: * add dmabupt to collaborators (Xu Meng) #37377 * refactor fs docs structure (James M Snell) #37170 * fs: * add fsPromises.watch() (James M Snell) #37179 * use a default callback for fs.close() (James M Snell) #37174 * add AbortSignal support to watch (Benjamin Gruenbaum) #37190 * perf_hooks: * introduce createHistogram (James M Snell) #37155 * stream: * improve Readable.from error handling (Benjamin Gruenbaum) #37158 * timers: * introduce setInterval async iterator (linkgoron) #37153 * tls: * add ability to get cert/peer cert as X509Certificate object (James M Snell) #37070
PR-URL: #37406 Notable Changes: * crypto: * add keyObject.export() jwk format option (Filip Skokan) #37081 * deps: * upgrade to libuv 1.41.0 (Colin Ihrig) #37360 * doc: * add dmabupt to collaborators (Xu Meng) #37377 * refactor fs docs structure (James M Snell) #37170 * fs: * add fsPromises.watch() (James M Snell) #37179 * use a default callback for fs.close() (James M Snell) #37174 * add AbortSignal support to watch (Benjamin Gruenbaum) #37190 * perf_hooks: * introduce createHistogram (James M Snell) #37155 * stream: * improve Readable.from error handling (Benjamin Gruenbaum) #37158 * timers: * introduce setInterval async iterator (linkgoron) #37153 * tls: * add ability to get cert/peer cert as X509Certificate object (James M Snell) #37070
PR-URL: #37406 Notable Changes: * crypto: * add keyObject.export() jwk format option (Filip Skokan) #37081 * deps: * upgrade to libuv 1.41.0 (Colin Ihrig) #37360 * doc: * add dmabupt to collaborators (Xu Meng) #37377 * refactor fs docs structure (James M Snell) #37170 * fs: * add fsPromises.watch() (James M Snell) #37179 * use a default callback for fs.close() (James M Snell) #37174 * add AbortSignal support to watch (Benjamin Gruenbaum) #37190 * perf_hooks: * introduce createHistogram (James M Snell) #37155 * stream: * improve Readable.from error handling (Benjamin Gruenbaum) #37158 * timers: * introduce setInterval async iterator (linkgoron) #37153 * tls: * add ability to get cert/peer cert as X509Certificate object (James M Snell) #37070
This pull request aligns the behaviour of
Readable.fromwith other stream behaviours namely:.throwand not via.onand reach catch blocks. This means things likeaddAbortSignalwork withReadable.fromnow.nextwas not called - this is because the previous implementation had a timing bug where ifnextwas called and the stream was destroyed in the same tick - finally blocks would not run.cc @ronag @mcollina @nodejs/streams