Skip to content

Race condition can cause the callinvoker to get a null runtime during… - #16186

Merged
acoates-ms merged 3 commits into
microsoft:mainfrom
acoates-ms:callinvokerace
May 26, 2026
Merged

acoates-ms merged 3 commits into
microsoft:mainfrom
acoates-ms:callinvokerace

Conversation

@acoates-ms

@acoates-ms acoates-ms commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

… shutdown. Which should just skip the invoke.

I'm not sure if this actually hits with the new arch, but it should be fine to add the extra protection.

This is from old arch on 0.81:
The thread destroying the instance will land here

 	[Inline Frame] react-native-win32.dll!facebook::react::NativeToJsBridge::destroy() Line 281	C++
 	react-native-win32.dll!facebook::react::Instance::~Instance() Line 39	C++
 	react-native-win32.dll!facebook::react::Instance::`scalar deleting destructor'(unsigned int)	
 	[Inline Frame] react-native-win32.dll!std::_Ref_count_base::_Decref() Line 1160	
 	[Inline Frame] react-native-win32.dll!std::_Ptr_base<facebook::react::Instance>::_Decref() Line 1385	
 	[Inline Frame] react-native-win32.dll!std::shared_ptr<facebook::react::Instance>::{dtor}() Line 1690	
 	react-native-win32.dll!Mso::React::ReactInstanceWin::Destroy() Line 1089	C++
 	[Inline Frame] react-native-win32.dll!Mso::React::ReactHost::UnloadInQueue::__l2::<lambda_2>::operator()(Mso::Maybe<void> &&) Line 595	C++
 	react-native-win32.dll!Mso::Executors::Internal::ExecutorInvoker::Invoke<`Mso::React::ReactHost::UnloadInQueue'::`2'::<lambda_2> &,Mso::Maybe<void>>(Mso::React::ReactHost::UnloadInQueue::__l2::<lambda_2> & callback, Mso::Maybe<void> && <args_0>) Line 203	C++

meanwhile a call on the JS thread was in progress:

 	<app>!winrt::Microsoft::ReactNative::GetOrCreateContextRuntime(const winrt::Microsoft::ReactNative::ReactContext & context, const winrt::Windows::Foundation::IInspectable & runtimeHandle) Line 90	C++
 	[Inline Frame] mso40uiwin32client.dll!winrt::Microsoft::ReactNative::AbiCallInvoker::invokeSync::__l2::<lambda_1>::operator()(const winrt::Windows::Foundation::IInspectable &) Line 25	C++
    app>!winrt::impl::delegate<winrt::Microsoft::ReactNative::CallFunc,`winrt::Microsoft::ReactNative::AbiCallInvoker::invokeSync'::`2'::<lambda_1>>::Invoke(void * runtime) Line 2636	C++
 	[Inline Frame] react-native-win32.dll!winrt::Microsoft::ReactNative::CallFunc::operator()(const winrt::Windows::Foundation::IInspectable &) Line 6964	C++
 	[Inline Frame] react-native-win32.dll!winrt::Microsoft::ReactNative::implementation::CallInvoker::InvokeSync::__l2::<lambda_1>::operator()(facebook::jsi::Runtime &) Line 28	C++
 	[Inline Frame] react-native-win32.dll!std::invoke(winrt::Microsoft::ReactNative::implementation::CallInvoker::InvokeSync::__l2::<lambda_1> &) Line 1680	
 	react-native-win32.dll!std::_Func_impl_no_alloc<`winrt::Microsoft::ReactNative::implementation::CallInvoker::InvokeSync'::`2'::<lambda_1>,void,facebook::jsi::Runtime &>::_Do_call(facebook::jsi::Runtime & <_Args_0>) Line 880	
 	[Inline Frame] react-native-win32.dll!std::_Func_class<void,facebook::jsi::Runtime &>::operator()(facebook::jsi::Runtime &) Line 926	
 	[Inline Frame] react-native-win32.dll!facebook::react::Instance::JSCallInvoker::scheduleAsync::__l5::<lambda_1>::operator()(facebook::react::JSExecutor * executor) Line 360	C++
 	[Inline Frame] react-native-win32.dll!std::invoke(facebook::react::Instance::JSCallInvoker::scheduleAsync::__l5::<lambda_1> &) Line 1680	
 	react-native-win32.dll!std::_Func_impl_no_alloc<`facebook::react::Instance::JSCallInvoker::scheduleAsync'::`5'::<lambda_1>,void,facebook::react::JSExecutor *>::_Do_call(facebook::react::JSExecutor * && <_Args_0>) Line 880	
 	[Inline Frame] react-native-win32.dll!std::_Func_class<void,facebook::react::JSExecutor *>::operator()(facebook::react::JSExecutor * <_Args_0>) Line 926	
 	[Inline Frame] react-native-win32.dll!facebook::react::NativeToJsBridge::runOnExecutorQueue::__l2::<lambda_1>::operator()() Line 306	C++
 	[Inline Frame] react-native-win32.dll!std::invoke(facebook::react::NativeToJsBridge::runOnExecutorQueue::__l2::<lambda_1> &) Line 1670	
Microsoft Reviewers: Open in CodeFlow

… shutdown. Which should just skip the invoke.
@acoates-ms
acoates-ms requested a review from a team as a code owner May 26, 2026 17:24
@github-actions

Copy link
Copy Markdown

Performance Test Results

Branch: callinvokerace
Commit: 36055ab4
Time: 2026-05-26T18:22:11.110Z
Tests: 161/161 passed

✅ Passed

161 scenario(s) across 28 suite(s) — no regressions

SectionList

Scenario Mean Median StdDev Renders vs Baseline
SectionList mount 4.10ms 4.00ms ±0.57ms 1 -20.0%
SectionList unmount 0.20ms 0.00ms ±0.42ms 0 +0.0%
SectionList rerender 9.30ms 9.50ms ±1.83ms 2 -9.5%
SectionList with-3-sections-15-items 4.30ms 4.00ms ±0.48ms 1 -27.3%
SectionList with-5-sections-50-items 5.30ms 5.00ms ±1.06ms 1 -16.7%
SectionList with-10-sections-200-items 4.80ms 5.00ms ±0.63ms 1 -9.1%
SectionList with-20-sections-200-items 4.40ms 5.00ms ±1.17ms 1 +0.0%
SectionList with-section-separator 2.30ms 2.00ms ±0.48ms 1 +0.0%
SectionList with-item-separator 2.00ms 2.00ms ±0.47ms 1 +0.0%
SectionList with-header-footer 1.60ms 1.50ms ±0.70ms 1 -25.0%
SectionList with-section-footer 1.40ms 1.00ms ±0.52ms 1 -50.0%
SectionList with-sticky-section-headers 1.90ms 1.50ms ±1.52ms 1 -25.0%
SectionList with-empty-list 0.50ms 0.50ms ±0.53ms 1 -50.0%
SectionList with-50-sections-1000-items 1.30ms 1.00ms ±0.48ms 1 -50.0%

FlatList

Scenario Mean Median StdDev Renders vs Baseline
FlatList mount 3.90ms 4.00ms ±1.20ms 1 +0.0%
FlatList unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
FlatList rerender 8.70ms 8.00ms ±2.00ms 2 -11.1%
FlatList with-10-items 4.00ms 4.00ms ±0.47ms 1 +0.0%
FlatList with-100-items 4.60ms 4.00ms ±1.07ms 1 -20.0%
FlatList with-500-items 4.10ms 4.00ms ±0.32ms 1 +0.0%
FlatList with-1000-items 4.30ms 4.00ms ±1.06ms 1 +0.0%
FlatList horizontal 3.60ms 4.00ms ±1.07ms 1 -20.0%
FlatList with-separator 1.60ms 1.50ms ±0.70ms 1 -25.0%
FlatList with-header-footer 1.40ms 1.00ms ±0.52ms 1 -50.0%
FlatList with-empty-list 0.50ms 0.50ms ±0.53ms 1 +0.0%
FlatList with-get-item-layout 1.40ms 1.00ms ±0.52ms 1 +0.0%
FlatList inverted 1.70ms 1.00ms ±1.89ms 1 -33.3%
FlatList with-num-columns 2.40ms 3.00ms ±0.84ms 1 +0.0%

TouchableOpacity

Scenario Mean Median StdDev Renders vs Baseline
TouchableOpacity mount 0.80ms 1.00ms ±0.42ms 1 +0.0%
TouchableOpacity unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
TouchableOpacity rerender 0.90ms 1.00ms ±0.32ms 2 +0.0%
TouchableOpacity custom-active-opacity 0.30ms 0.00ms ±0.48ms 1 -100.0%
TouchableOpacity disabled 0.50ms 0.50ms ±0.53ms 1 -50.0%
TouchableOpacity with-all-handlers 0.50ms 0.50ms ±0.53ms 1 -50.0%
TouchableOpacity with-hit-slop 0.60ms 1.00ms ±0.52ms 1 +0.0%
TouchableOpacity with-delay 0.60ms 1.00ms ±0.52ms 1 +0.0%
TouchableOpacity nested 1.30ms 1.00ms ±0.48ms 1 +0.0%
TouchableOpacity multiple-10 4.40ms 4.00ms ±0.91ms 1 -33.3%
TouchableOpacity multiple-50 22.27ms 22.00ms ±2.25ms 1 -24.1%
TouchableOpacity multiple-100 21.00ms 20.00ms ±6.19ms 1 -60.0%

ScrollView

Scenario Mean Median StdDev Renders vs Baseline
ScrollView mount 0.30ms 0.00ms ±0.48ms 1 +0.0%
ScrollView unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
ScrollView rerender 0.50ms 0.50ms ±0.53ms 2 -50.0%
ScrollView children-20 2.80ms 3.00ms ±0.41ms 1 -25.0%
ScrollView children-100 14.87ms 14.00ms ±2.33ms 1 -12.5%
ScrollView horizontal 2.80ms 3.00ms ±0.42ms 1 -25.0%
ScrollView sticky-headers 2.30ms 2.50ms ±0.82ms 1 -16.7%
ScrollView scroll-indicators 1.20ms 1.00ms ±1.40ms 1 +0.0%
ScrollView nested 1.00ms 1.00ms ±0.00ms 1 +0.0%
ScrollView content-container-style 0.70ms 1.00ms ±0.48ms 1 +0.0%
ScrollView children-500 19.40ms 18.00ms ±3.09ms 1 -5.3%

TouchableHighlight

Scenario Mean Median StdDev Renders vs Baseline
TouchableHighlight mount 0.50ms 0.50ms ±0.53ms 1 +0.0%
TouchableHighlight unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
TouchableHighlight rerender 0.60ms 1.00ms ±0.52ms 2 +0.0%
TouchableHighlight custom-underlay-color 0.40ms 0.00ms ±0.52ms 1 +0.0%
TouchableHighlight custom-active-opacity 0.30ms 0.00ms ±0.48ms 1 +0.0%
TouchableHighlight disabled 0.40ms 0.00ms ±0.52ms 1 +0.0%
TouchableHighlight with-all-handlers 0.20ms 0.00ms ±0.42ms 1 +0.0%
TouchableHighlight with-hit-slop 0.80ms 0.00ms ±1.55ms 1 +0.0%
TouchableHighlight nested-touchables 0.60ms 1.00ms ±0.52ms 1 +0.0%
TouchableHighlight multiple-touchables-10 2.00ms 2.00ms ±0.67ms 1 -33.3%
TouchableHighlight multiple-touchables-50 11.80ms 11.00ms ±2.30ms 1 -12.0%
TouchableHighlight multiple-touchables-100 23.70ms 24.00ms ±3.86ms 1 +6.7%

Pressable

Scenario Mean Median StdDev Renders vs Baseline
Pressable mount 0.40ms 0.00ms ±0.52ms 1 +0.0%
Pressable unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
Pressable rerender 0.50ms 0.50ms ±0.53ms 2 +0.0%
Pressable with-all-handlers 0.20ms 0.00ms ±0.42ms 1 +0.0%
Pressable with-style-function 0.40ms 0.00ms ±0.52ms 1 +0.0%
Pressable disabled 0.40ms 0.00ms ±0.52ms 1 +0.0%
Pressable with-hit-slop 0.30ms 0.00ms ±0.48ms 1 +0.0%
Pressable nested 0.50ms 0.50ms ±0.53ms 1 -50.0%
Pressable multiple-10 2.73ms 2.00ms ±1.33ms 1 -33.3%
Pressable multiple-50 13.40ms 13.00ms ±1.45ms 1 -7.1%
Pressable multiple-100 14.60ms 11.00ms ±8.35ms 1 -8.3%

Modal

Scenario Mean Median StdDev Renders vs Baseline
Modal mount 0.30ms 0.00ms ±0.48ms 1 +0.0%
Modal unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
Modal rerender 0.30ms 0.00ms ±0.48ms 2 +0.0%
Modal slide-animation 0.10ms 0.00ms ±0.32ms 1 +0.0%
Modal fade-animation 0.30ms 0.00ms ±0.48ms 1 +0.0%
Modal transparent 0.20ms 0.00ms ±0.42ms 1 +0.0%
Modal with-callbacks 0.20ms 0.00ms ±0.42ms 1 +0.0%
Modal rich-content 1.10ms 1.00ms ±0.32ms 1 -50.0%
Modal with-accessibility 0.30ms 0.00ms ±0.48ms 1 +0.0%

Image

Scenario Mean Median StdDev Renders vs Baseline
Image mount 0.00ms 0.00ms ±0.00ms 1 +0.0%
Image unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
Image rerender 0.10ms 0.00ms ±0.32ms 2 +0.0%
Image with-resize-mode 0.10ms 0.00ms ±0.32ms 1 +0.0%
Image with-border-radius 0.10ms 0.00ms ±0.32ms 1 +0.0%
Image with-tint-color 0.00ms 0.00ms ±0.00ms 1 +0.0%
Image with-blur-radius 0.20ms 0.00ms ±0.42ms 1 +0.0%
Image with-accessibility 0.00ms 0.00ms ±0.00ms 1 +0.0%
Image multiple-10 0.73ms 1.00ms ±0.46ms 1 +0.0%
Image multiple-50 3.33ms 3.00ms ±0.49ms 1 +0.0%
Image multiple-100 7.53ms 7.00ms ±1.64ms 1 -12.5%

ActivityIndicator

Scenario Mean Median StdDev Renders vs Baseline
ActivityIndicator mount 0.10ms 0.00ms ±0.32ms 1 +0.0%
ActivityIndicator unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
ActivityIndicator rerender 0.10ms 0.00ms ±0.32ms 2 +0.0%
ActivityIndicator size-large 0.10ms 0.00ms ±0.32ms 1 +0.0%
ActivityIndicator size-small 0.10ms 0.00ms ±0.32ms 1 +0.0%
ActivityIndicator with-color 0.00ms 0.00ms ±0.00ms 1 +0.0%
ActivityIndicator not-animating 0.10ms 0.00ms ±0.32ms 1 +0.0%
ActivityIndicator with-accessibility 0.10ms 0.00ms ±0.32ms 1 +0.0%
ActivityIndicator multiple-10 1.13ms 1.00ms ±1.13ms 1 +0.0%
ActivityIndicator multiple-50 3.07ms 3.00ms ±0.46ms 1 -25.0%
ActivityIndicator multiple-100 7.53ms 7.00ms ±1.68ms 1 +0.0%

Switch

Scenario Mean Median StdDev Renders vs Baseline
Switch mount 0.20ms 0.00ms ±0.42ms 1 +0.0%
Switch unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
Switch rerender 0.40ms 0.00ms ±0.52ms 2 -100.0%
Switch value-true 0.20ms 0.00ms ±0.42ms 1 +0.0%
Switch disabled 0.10ms 0.00ms ±0.32ms 1 +0.0%
Switch custom-colors 0.20ms 0.00ms ±0.42ms 1 +0.0%
Switch on-value-change 0.20ms 0.00ms ±0.42ms 1 +0.0%
Switch with-accessibility 0.10ms 0.00ms ±0.32ms 1 +0.0%
Switch multiple-10 1.60ms 1.00ms ±1.30ms 1 -50.0%
Switch multiple-50 8.80ms 7.00ms ±3.14ms 1 -22.2%
Switch multiple-100 17.00ms 14.00ms ±4.11ms 1 -12.5%

Button

Scenario Mean Median StdDev Renders vs Baseline
Button mount 0.90ms 1.00ms ±0.32ms 1 +0.0%
Button unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
Button rerender 1.30ms 1.50ms ±0.82ms 2 +50.0%
Button disabled 1.00ms 1.00ms ±0.00ms 1 +0.0%
Button with-color 0.70ms 1.00ms ±0.48ms 1 +100.0%
Button with-accessibility 0.70ms 1.00ms ±0.48ms 1 +0.0%
Button multiple-10 5.80ms 5.00ms ±1.82ms 1 -16.7%
Button multiple-50 19.00ms 22.00ms ±6.55ms 1 -18.5%
Button multiple-100 14.27ms 14.00ms ±1.94ms 1 -26.3%

TextInput

Scenario Mean Median StdDev Renders vs Baseline
TextInput mount 0.30ms 0.00ms ±0.48ms 1 +0.0%
TextInput unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
TextInput rerender 0.30ms 0.00ms ±0.48ms 2 +0.0%
TextInput multiline 0.20ms 0.00ms ±0.42ms 1 +0.0%
TextInput with-value 0.10ms 0.00ms ±0.32ms 1 +0.0%
TextInput styled 0.20ms 0.00ms ±0.42ms 1 +0.0%
TextInput multiple-100 6.47ms 6.00ms ±1.55ms 1 -14.3%

View

Scenario Mean Median StdDev Renders vs Baseline
View mount 0.10ms 0.00ms ±0.32ms 1 +0.0%
View unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
View rerender 0.10ms 0.00ms ±0.32ms 2 +0.0%
View nested-50 2.93ms 3.00ms ±0.26ms 1 +0.0%
View nested-100 6.80ms 7.00ms ±0.86ms 1 +0.0%
View shadow 0.00ms 0.00ms ±0.00ms 1 +0.0%
View border-radius 0.00ms 0.00ms ±0.00ms 1 +0.0%
View nested-500 16.07ms 9.00ms ±11.75ms 1 -10.0%

Text

Scenario Mean Median StdDev Renders vs Baseline
Text mount 0.20ms 0.00ms ±0.42ms 1 +0.0%
Text unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
Text rerender 0.00ms 0.00ms ±0.00ms 2 +0.0%
Text long-1000 0.10ms 0.00ms ±0.32ms 1 +0.0%
Text nested 0.30ms 0.00ms ±0.48ms 1 +0.0%
Text styled 0.20ms 0.00ms ±0.42ms 1 +0.0%
Text multiple-100 7.33ms 7.00ms ±2.16ms 1 +0.0%

SectionList.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
SectionList native mount 4.25ms 4.21ms ±0.42ms 1 -35.3%

FlatList.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
FlatList native mount 4.96ms 4.18ms ±1.58ms 1 -54.7%

TouchableHighlight.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
TouchableHighlight native mount 1.37ms 1.30ms ±0.19ms 1 -37.6%

TouchableOpacity.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
TouchableOpacity native mount 1.61ms 1.64ms ±0.19ms 1 -47.6%

Pressable.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Pressable native mount 1.38ms 1.33ms ±0.11ms 1 -47.1%

ScrollView.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
ScrollView native mount 3.02ms 2.97ms ±0.30ms 1 -26.6%

ActivityIndicator.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
ActivityIndicator native mount 1.39ms 1.15ms ±0.81ms 1 -53.5%

TextInput.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
TextInput native mount 1.84ms 1.80ms ±0.18ms 1 -56.0%

Switch.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Switch native mount 1.02ms 1.00ms ±0.11ms 1 -42.4%

Button.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Button native mount 1.54ms 1.51ms ±0.13ms 1 -41.9%

Modal.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Modal native mount 0.84ms 0.79ms ±0.19ms 1 -35.5%

Image.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Image native mount 1.45ms 1.45ms ±0.12ms 1 -36.0%

View.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
View native mount 0.97ms 0.92ms ±0.20ms 1 -35.7%

Text.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Text native mount 1.15ms 1.10ms ±0.18ms 1 -36.6%

@acoates-ms
acoates-ms merged commit b70d8f8 into microsoft:main May 26, 2026
33 checks passed
@acoates-ms
acoates-ms deleted the callinvokerace branch May 26, 2026 20:03
acoates-ms added a commit that referenced this pull request May 26, 2026
#16186) (#16187)

* Race condition can cause the callinvoker to get a null runtime during shutdown.  Which should just skip the invoke.

* Change files
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.

2 participants