Skip to content

fix: settle pending upload stream reads when a net.request ends - #53368

Merged
MarshallOfSound merged 4 commits into
45-x-yfrom
trop/45-x-y-bp-fix-settle-pending-upload-stream-reads-when-a-net-request-ends-1788276714040
Sep 1, 2026
Merged

MarshallOfSound merged 4 commits into
45-x-yfrom
trop/45-x-y-bp-fix-settle-pending-upload-stream-reads-when-a-net-request-ends-1788276714040

Conversation

@trop

@trop trop Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Backport of #53341

See that PR for details.

Notes: Fixed a pending read on a net.request chunked upload stream inside a protocol handler never settling when the request failed or was aborted.

trop Bot and others added 4 commits September 1, 2026 15:32
When a protocol handler reads the chunked upload body of a net.request
through the stream it is handed, and the request then fails or is aborted,
the handler's pending read was never settled: nothing told the
JSChunkedDataPipeGetter that the request was over, so the GetSize reply the
stream waits on never arrived and its SelfKeepAlive rooted it forever.

Abort the getter from SimpleURLLoaderWrapper::OnComplete and Cancel so the
stream's pending read rejects with the request's net error.

This is also what made the cpp-heap ChunkedDataPipeReadableStream spec hang
under ASan/UBSan: its handler drops the one-time protocol callback, which
is only weakly referenced from C++, so the test's own GC loop could collect
it and fail the request with ERR_FAILED before request.end() ran. The test
now holds the callback for its duration, and a new net spec covers the
abort path directly.

Co-authored-by: Sam Attard <[email protected]>
ASan on CI caught a use-after-poison in mojo::ReceiverSetState::Entry::
OnDisconnect. The poison history shows cppgc's UnmarkedObjectsPoisoner
poisoning a SimpleURLLoaderWrapper at the start of a sweep, i.e. after the
GC found it dead but before its destructor ran; the network service's
disconnect for one of the wrapper's URLLoaderNetworkServiceObserver
receivers then landed on the dead object. UtilityProcessWrapper owns the
same kind of ReceiverSet for a utility process's requests.

Give both a cppgc pre-finalizer that drops the receivers before the sweep,
the pattern ReplyChannel and the IPC renderer objects already use.

Also from review:
- Abort() only resets the chunked getter instead of answering GetSize with
  an error, which the network service DCHECKs against; consumers already
  treat the disconnect as the body ending with ERR_FAILED, so a handler's
  pending read reports the request failure rather than the abort.
- A write still in flight when the request ends is rejected with
  ERR_ABORTED instead of never settling, and the request's internal body
  stream no longer re-raises that as an unhandled error.

Co-authored-by: Sam Attard <[email protected]>
…lloaderwrapper (#53358)

* refactor: move utility process network observer off cppgc heap

Store URLLoaderNetworkObserver in a separate allocation so its mojo receivers
remain accessible while UtilityProcessWrapper is awaiting cppgc sweeping.
This avoids requiring a prefinalizer to disconnect the receivers.

* refactor: move URL loader callbacks off cppgc heap

Route stream and network observer callbacks through a separately allocated
client holding a weak reference to SimpleURLLoaderWrapper. This keeps mojo
dispatch state valid during cppgc sweeping without requiring a prefinalizer.

Co-authored-by: Robo <[email protected]>
… is aborted

ChunkedBodyStream dropped the pending first-chunk write callback on abort,
so the caller's write callback never fired. Let it settle with the abort
error instead, which is what Node.js does (ECANCELED); no 'error' event
follows because the request is already destroyed by the time it lands.

Co-authored-by: Sam Attard <[email protected]>
@trop
trop Bot requested a review from MarshallOfSound September 1, 2026 15:32
@trop trop Bot added 45-x-y backport This is a backport PR semver/patch backwards-compatible bug fixes labels Sep 1, 2026
@MarshallOfSound
MarshallOfSound enabled auto-merge (squash) September 1, 2026 16:04
@MarshallOfSound
MarshallOfSound merged commit 8e2af2d into 45-x-y Sep 1, 2026
147 of 149 checks passed
@MarshallOfSound
MarshallOfSound deleted the trop/45-x-y-bp-fix-settle-pending-upload-stream-reads-when-a-net-request-ends-1788276714040 branch September 1, 2026 22:29
@release-clerk

release-clerk Bot commented Sep 1, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed a pending read on a net.request chunked upload stream inside a protocol handler never settling when the request failed or was aborted.

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

Labels

45-x-y backport This is a backport PR semver/patch backwards-compatible bug fixes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants