Skip to content

refactor: remove prefinalizer from utilityprocesswrapper and simpleurlloaderwrapper - #53358

Merged
MarshallOfSound merged 2 commits into
fix/chunked-upload-stream-hangfrom
robo/chunked-upload-stream-hang-refactor
Sep 1, 2026
Merged

MarshallOfSound merged 2 commits into
fix/chunked-upload-stream-hangfrom
robo/chunked-upload-stream-hang-refactor

Conversation

@deepak1556

Copy link
Copy Markdown
Member

Description of Change

Followup to #53341

cppgc prefinalizer should be a last resort because every registered prefinalizer must be examined during garbage collection, adding per object storage and GC overhead.

Release Notes

Notes: none

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.
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.
@deepak1556 deepak1556 added backport-check-skip Skip trop's backport validity checking semver/none labels Sep 1, 2026
@MarshallOfSound
MarshallOfSound merged commit 994ea77 into fix/chunked-upload-stream-hang Sep 1, 2026
89 checks passed
@MarshallOfSound
MarshallOfSound deleted the robo/chunked-upload-stream-hang-refactor branch September 1, 2026 05:54
@release-clerk

release-clerk Bot commented Sep 1, 2026

Copy link
Copy Markdown

No Release Notes

MarshallOfSound added a commit that referenced this pull request Sep 1, 2026
* fix: settle pending upload stream reads when a net.request ends

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]>

* fix: drop mojo receivers before cppgc sweeps a dead request wrapper

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]>

* refactor: remove prefinalizer from utilityprocesswrapper and simpleurlloaderwrapper (#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]>

* fix: settle a chunked upload write that is in flight when the request 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]>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Sam Attard <[email protected]>
Co-authored-by: Robo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-check-skip Skip trop's backport validity checking semver/none

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants