Skip to content

fix(fetch): guard stream close after cancellation - #5716

Open
mcollina wants to merge 1 commit into
mainfrom
fix/readable-stream-from-cancel-race
Open

fix(fetch): guard stream close after cancellation#5716
mcollina wants to merge 1 commit into
mainfrom
fix/readable-stream-from-cancel-race

Conversation

@mcollina

Copy link
Copy Markdown
Member

This relates to...

Fixes #5715.

Rationale

ReadableStreamFrom defers closing its controller after an async iterator finishes. If the consumer cancels while iterator.next() is still pending, the delayed close runs against an already-closed controller and throws an uncatchable ERR_INVALID_STATE.

Changes

Features

N/A

Bug Fixes

  • Ignore the recognized already-closed controller errors when cancellation wins the race with the delayed close.
  • Re-throw unexpected controller errors.
  • Add a deterministic regression test that cancels while iterator.next() is in flight.

Breaking Changes and Deprecations

N/A

Status

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@codecov-commenter

codecov-commenter commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.48%. Comparing base (5033aa1) to head (824414c).

Files with missing lines Patch % Lines
lib/core/util.js 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5716      +/-   ##
==========================================
+ Coverage   93.47%   93.48%   +0.01%     
==========================================
  Files         110      110              
  Lines       38906    38916      +10     
==========================================
+ Hits        36366    36380      +14     
+ Misses       2540     2536       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReadableStreamFrom: unguarded delayed controller.close() throws uncatchable ERR_INVALID_STATE when an async-iterable body is cancelled

2 participants