Skip to content

EventTarget::release: guard unsigned retainCount_ decrement and drop tautological assert#56490

Open
meta-yaohway wants to merge 2 commits intofacebook:mainfrom
meta-yaohway:export-D100280458
Open

EventTarget::release: guard unsigned retainCount_ decrement and drop tautological assert#56490
meta-yaohway wants to merge 2 commits intofacebook:mainfrom
meta-yaohway:export-D100280458

Conversation

@meta-yaohway
Copy link
Copy Markdown

Summary: Changelog: [Internal]

Reviewed By: javache

Differential Revision: D100280458

…ss throwing JS dispatch

Summary:
`EventQueueProcessor::flushEvents` retains every `EventTarget` in the batch, then for each event calls `eventPipe_` (which dispatches into JS via `UIManagerBinding::dispatchEventToJS` and can throw `jsi::JSError`), then `eventPipeConclusion_`, and finally runs a trailing loop that calls `event.eventTarget->release(runtime)`. If either pipe call throws, stack unwinding skips the release loop, leaving `strongInstanceHandle_` (a `jsi::Value` strong reference to the JS event-target object) pinned and `retainCount_` desynchronised.

This change replaces the trailing release loop with an inline `EventTargetReleaseGuard` RAII object constructed immediately after the retain pass. Its destructor releases every retained target on every exit path — normal return, `eventPipe_` throw, or `eventPipeConclusion_` throw.

Behaviour-preserving on the happy path: same release ordering (after `eventPipeConclusion_`), same no-`DispatchMutex` policy for release (the `events` vector still holds the strong `shared_ptr`s), zero added allocation (the guard holds two references).

Adds `EventQueueProcessorTest.releasesEventTargetsWhenDispatchThrows`: builds a processor whose `eventPipe_` unconditionally throws, dispatches one event with a real `EventTarget`, asserts the call throws, then asserts `eventTarget->getInstanceHandle(runtime).isNull()` — i.e. the strong handle was released during unwind. This test fails (returns the still-pinned object) on the pre-fix trailing-loop code.

Changelog: [Internal]

Differential Revision: D100280132
…tautological assert

Summary: Changelog: [Internal]

Reviewed By: javache

Differential Revision: D100280458
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 18, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync bot commented Apr 18, 2026

@meta-yaohway has exported this pull request. If you are a Meta employee, you can view the originating Diff in D100280458.

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant