Repository navigation
Wait for sync access requests to be queued in RuntimeSchedulerTest - #60584
Open
YevheniiKotyrlo wants to merge 1 commit into
Open
YevheniiKotyrlo wants to merge 1 commit into
YevheniiKotyrlo wants to merge 1 commit into
Conversation
`executeNowOnTheSameThread` makes `getShouldYield()` true before it queues its task on the runtime executor. `normalTaskYieldsToSynchronousAccess` and `immediateTaskYieldsToSynchronousAccess` checked the stub queue as soon as the yielding task returned, and `modernTwoThreadsRequestAccessToTheRuntime` let the first sync task finish after a fixed 50 ms, so each passed only if the other thread had queued its request by then. I wait on `StubQueue::waitForTask()` in all three; `normalTaskYieldsToSynchronousAccessAndResumes` has waited on the stub queue the same way since react#50854. Signed-off-by: YevheniiKotyrlo <44449990+YevheniiKotyrlo@users.noreply.github.com>
YevheniiKotyrlo
force-pushed
the
fix/runtime-scheduler-test-sync-access-race
branch
from
December 4, 2026 23:58
46a3479 to
1e4b13c
Compare
YevheniiKotyrlo
marked this pull request as ready for review
December 5, 2026 01:27
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
RuntimeScheduler_Modern::executeNowOnTheSameThreadincrementssyncTaskRequests_, which makesgetShouldYield()true, beforeexecuteSynchronouslyOnSameThread_CAN_DEADLOCKqueues its task on the runtime executor. Three tests inRuntimeSchedulerTest.cppassert on that queued task without waiting for it:normalTaskYieldsToSynchronousAccessandimmediateTaskYieldsToSynchronousAccesscheckstubQueue_->size()as soon as the yielding task returns fromtick().immediateTaskYieldsToSynchronousAccess/1failed this way once in a local run of thetest_react_common_cxxjob's steps, 1 of its 1655 tests, withstubQueue_->size()0 where it expects 1.modernTwoThreadsRequestAccessToTheRuntimelets the first sync task finish after a fixed 50 ms sleep, so the checks aftert1.join()hold only if the second thread has queued its request by then.The first two now wait on
stubQueue_->waitForTask()after thetick(). In the third, the first sync task waits onstubQueue_->waitForTask()in place of the semaphore and the sleeping thread: while it runs, the main thread is inside thetick()that started it, so the queue is empty until the second thread queues its request.normalTaskYieldsToSynchronousAccessAndResumeshas waited on the stub queue the same way since #50854, withstubQueue_->waitForTasks(2).Changelog:
[INTERNAL] [FIXED] - Wait for sync access requests to be queued in RuntimeSchedulerTest
Test Plan:
In
reactnativecommunity/react-native-android:latest, with clang 18 installed as thetest_react_common_cxxjob installs it:The sync access tests (
normalTaskYieldsToSynchronousAccess,normalTaskYieldsToSynchronousAccessAndResumes,immediateTaskYieldsToSynchronousAccess,legacyTwoThreadsRequestAccessToTheRuntime,modernTwoThreadsRequestAccessToTheRuntime, under both params), built the same way and run 1000 times in one process:Each of the 1000 iterations ends with
[ PASSED ] 10 tests.node ./scripts/clang-format.js packages/react-native/ReactCommon/react/renderer/runtimescheduler/tests/RuntimeSchedulerTest.cpp, which runs the clang-format 21.1.2 thatscripts/clang-formatpins, leaves the file unchanged.