Skip to content

Wait for sync access requests to be queued in RuntimeSchedulerTest - #60584

Open
YevheniiKotyrlo wants to merge 1 commit into
react:mainfrom
YevheniiKotyrlo:fix/runtime-scheduler-test-sync-access-race
Open

YevheniiKotyrlo wants to merge 1 commit into
react:mainfrom
YevheniiKotyrlo:fix/runtime-scheduler-test-sync-access-race

Conversation

@YevheniiKotyrlo

Copy link
Copy Markdown
Contributor

Summary:

RuntimeScheduler_Modern::executeNowOnTheSameThread increments syncTaskRequests_, which makes getShouldYield() true, before executeSynchronouslyOnSameThread_CAN_DEADLOCK queues its task on the runtime executor. Three tests in RuntimeSchedulerTest.cpp assert on that queued task without waiting for it:

  • normalTaskYieldsToSynchronousAccess and immediateTaskYieldsToSynchronousAccess check stubQueue_->size() as soon as the yielding task returns from tick(). immediateTaskYieldsToSynchronousAccess/1 failed this way once in a local run of the test_react_common_cxx job's steps, 1 of its 1655 tests, with stubQueue_->size() 0 where it expects 1.
  • modernTwoThreadsRequestAccessToTheRuntime lets the first sync task finish after a fixed 50 ms sleep, so the checks after t1.join() hold only if the second thread has queued its request by then.

The first two now wait on stubQueue_->waitForTask() after the tick(). In the third, the first sync task waits on stubQueue_->waitForTask() in place of the semaphore and the sleeping thread: while it runs, the main thread is inside the tick() that started it, so the queue is empty until the second thread queues its request. normalTaskYieldsToSynchronousAccessAndResumes has waited on the stub queue the same way since #50854, with stubQueue_->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 the test_react_common_cxx job installs it:

CC=clang-18 CXX=clang++-18 ./gradlew :private:react-native-fantom:configureFantomTester
$ANDROID_SDK_ROOT/cmake/3.30.5/bin/cmake --build private/react-native-fantom/build/tester --target react_renderer_runtimescheduler_tests -j"$(nproc)"
$ANDROID_SDK_ROOT/cmake/3.30.5/bin/ctest --test-dir private/react-native-fantom/build/tester/react-common-tests -R 'react/renderer/runtimescheduler/tests/' --output-on-failure
[…]
100% tests passed, 0 tests failed out of 102

The sync access tests (normalTaskYieldsToSynchronousAccess, normalTaskYieldsToSynchronousAccessAndResumes, immediateTaskYieldsToSynchronousAccess, legacyTwoThreadsRequestAccessToTheRuntime, modernTwoThreadsRequestAccessToTheRuntime, under both params), built the same way and run 1000 times in one process:

private/react-native-fantom/build/tester/react-common-tests/react_renderer_runtimescheduler_tests --gtest_filter='*SynchronousAccess*:*TwoThreadsRequestAccessToTheRuntime*' --gtest_repeat=1000
Repeating all tests (iteration 1000) . . .
[…]
[==========] 10 tests from 1 test suite ran. (47 ms total)
[  PASSED  ] 10 tests.

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 that scripts/clang-format pins, leaves the file unchanged.

`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
YevheniiKotyrlo force-pushed the fix/runtime-scheduler-test-sync-access-race branch from 46a3479 to 1e4b13c Compare December 4, 2026 23:58
@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as ready for review December 5, 2026 01:27

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant