Skip to content

Conversation

@Zaggy1024
Copy link
Contributor

@Zaggy1024 Zaggy1024 commented Dec 2, 2025

The DeferredInvocationContext only existed to satisfy the requirement in ThreadEventQueue that each event has an EventReceiver. However, deferred_invoke() was not even using the EventReceiver to call its callback. Therefore, we don't need to allocate one for every deferred invocation.

This also prevents WeakPtr::strong_ref() from racing and leaking the context object when invoking a function across threads.

@Zaggy1024 Zaggy1024 marked this pull request as draft December 2, 2025 17:28
@Zaggy1024 Zaggy1024 force-pushed the deferred-invoke-race-condition branch 2 times, most recently from f9bb2b0 to 32e969b Compare December 2, 2025 21:39
@Zaggy1024 Zaggy1024 changed the title LibCore: Only destroy deferred invoke contexts inside the event loop LibCore: Remove the dummy EventReceiver from deferred_invoke() Dec 2, 2025
@Zaggy1024 Zaggy1024 force-pushed the deferred-invoke-race-condition branch from 32e969b to 44d40fa Compare December 2, 2025 22:23
@Zaggy1024 Zaggy1024 marked this pull request as ready for review December 2, 2025 22:23
@R-Goc
Copy link
Contributor

R-Goc commented Dec 2, 2025

Could this get tested against the Windows CI as well?

@Zaggy1024 Zaggy1024 force-pushed the deferred-invoke-race-condition branch from 44d40fa to 3202553 Compare December 2, 2025 23:06
@Zaggy1024
Copy link
Contributor Author

Ah, good point, I'll add the windows label.

@Zaggy1024 Zaggy1024 added the windows Related to the Windows platform; on PRs this triggers a Windows CI build label Dec 2, 2025
@Zaggy1024 Zaggy1024 force-pushed the deferred-invoke-race-condition branch from 3202553 to 8088588 Compare December 2, 2025 23:09
The DeferredInvocationContext only existed to satisfy the requirement
in ThreadEventQueue that each event has an EventReceiver. However,
deferred_invoke() was not even using the EventReceiver to call its
callback. Therefore, we don't need to allocate one for every deferred
invocation.

This also prevents WeakPtr::strong_ref() from racing and leaking the
context object when invoking a function across threads.
@Zaggy1024 Zaggy1024 force-pushed the deferred-invoke-race-condition branch from 8088588 to f5e61b9 Compare December 3, 2025 02:59
@Zaggy1024 Zaggy1024 enabled auto-merge (rebase) December 3, 2025 02:59
@Zaggy1024 Zaggy1024 merged commit b572ae9 into LadybirdBrowser:master Dec 3, 2025
10 checks passed
@Zaggy1024 Zaggy1024 deleted the deferred-invoke-race-condition branch December 3, 2025 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

windows Related to the Windows platform; on PRs this triggers a Windows CI build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants