stream: fix addAbortSignal() for web streams - #62450
Conversation
|
Review requested:
|
MattiasBuelens
left a comment
There was a problem hiding this comment.
I believe this is a breaking change for WritableStreams.
I think this PR is a good change: using controller.error from a consumer API is fundamentally wrong, and we got this wrong from the start in #46273. But that does mean this PR is a semver-major change.
While we're at it, I think we should fix the behavior for ReadableStreams too to call readableStreamCancel instead.
@nodejs/streams Thoughts?
MattiasBuelens
left a comment
There was a problem hiding this comment.
Looks pretty good. Maybe this might not be as breaking of a change after all?
We'll need to update the docs though:
- Explain that for web streams, this will now call
cancel(forReadableStream) andabort(forWritableStream). - Add this PR to the
changesfrontmatter forstream.addAbortSignal.
|
@MattiasBuelens Compared to
The second part is the intentional change, since it lets the source clean up. I also checked the For
That also comes with a few side effects compared to
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62450 +/- ##
==========================================
+ Coverage 90.15% 90.16% +0.01%
==========================================
Files 746 746
Lines 242648 242660 +12
Branches 45720 45724 +4
==========================================
+ Hits 218758 218802 +44
+ Misses 15397 15364 -33
- Partials 8493 8494 +1
🚀 New features to boost your workflow:
|
|
This pull request has been marked as stale due to 90 days of inactivity. |
aa45438 to
dcb46ab
Compare
Signed-off-by: 池下 克彦 <kik@nvstl.com>
Signed-off-by: 池下 克彦 <kik@nvstl.com>
Signed-off-by: 池下 克彦 <kik@nvstl.com>
dcb46ab to
113374f
Compare
|
The tree is byte-identical to 79df0f7 merged with main, but the history changed:
Could you review once again? @MattiasBuelens |
MattiasBuelens
left a comment
There was a problem hiding this comment.
LGTM. However, I'd like someone else from @nodejs/streams to also have a look and help decide whether this new behavior is okay.
This fixes
stream.addAbortSignal()for web streams.addAbortSignal()usedkControllerErrorFunction, which mixed stream erroringwith abort handling.
For readable byte streams,
ReadableByteStreamControllerleft the default no-ophook in place, so
addAbortSignal()could not abort the stream.For writable streams,
WritableStreamDefaultControllerwired the hook tocontroller.error(), so the stream became errored butcontroller.signal.abortedstayedfalse.This replaces
kControllerErrorFunctionwithkControllerAbortFunctionandwires each controller to the internal operation that matches its abort path:
ReadableStreamDefaultControllerusesreadableStreamDefaultControllerError()ReadableByteStreamControllerusesreadableByteStreamControllerError()WritableStreamDefaultControlleruseswritableStreamAbort()The updated test covers
addAbortSignal()on readable byte streams, abortsthat race with pending pulls, writable abort signal state, and readable and
writable controllers with overridden public methods.