SIGN IN SIGN UP
facebook / react-native UNCLAIMED

A framework for building native applications using React

0 0 154 C++

Add unit test for RuntimeExecutor post-shutdown safety (#56995)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/56995

The `RuntimeExecutor` returned by `ReactInstance::getBufferedRuntimeExecutor()` is designed to be safe to hold past the lifetime of the `ReactInstance` itself — callers may schedule work on it after shutdown without crashing, and any pending callbacks must be dropped rather than surfaced on the JS queue.

This contract relies on `weak_ptr` captures inside the executor closure and inside the base closure in the `ReactInstance` constructor. Today nothing tests it directly — coverage is incidental through `ReactInstanceTest` happy-path cases — so a future refactor that swaps a `weak_ptr` capture for a `shared_ptr` (keeping the runtime alive) or a raw pointer (introducing UAF) could silently regress.

Adds three focused regression tests covering:

- Calling the held executor after `ReactInstance` destruction drops the callback (no queuing, no execution).
- Repeated post-shutdown invocations remain memory-safe.
- Work buffered in `BufferedRuntimeExecutor` before shutdown is dropped, never surfaced on the JS queue.

The new test file lands under the existing `tests` target's `glob(["tests/**/*.cpp"])`, so no BUCK changes are needed.

Note: this test deliberately targets the buffered API only. `getUnbufferedRuntimeExecutor()` captures `runtimeScheduler_.get()` as a raw pointer and is not safe to hold past shutdown by design — a separate concern, out of scope here.

Changelog:
[Internal]

___

Differential Revision: D106783789

fbshipit-source-id: d28f07d9c79daf8596415686f17e6352c34dfb29
P
Pieter De Baets committed
b043c2757b7f76c769e21475ea2399fe04607c67
Parent: 707e366
Committed by meta-codesync[bot] <215208954+meta-codesync[bot]@users.noreply.github.com> on 5/29/2026, 11:32:07 AM