Skip to content

Commit 9cbddbd

Browse files
sammy-SCmeta-codesync[bot]
authored andcommitted
Clear RuntimeScheduler queues on error (#56892)
Summary: Pull Request resolved: #56892 changelog: [internal] Add `enableRuntimeSchedulerQueueClearingOnError` and use it in `RuntimeScheduler_Modern` to clear pending tasks, pending rendering updates, and pending surface IDs before forwarding task or microtask errors to `onTaskError`. Update `SchedulerDelegateInvalidationTest` so `enableSchedulerDelegateInvalidation` can be disabled while the new queue-clearing flag is enabled, proving that stale rendering updates and queued follow-up tasks are dropped after an error. Reviewed By: christophpurrer Differential Revision: D105696366 fbshipit-source-id: 24aa04a8084fb1534bb85785558b503bb8cf619c
1 parent 6dd2cac commit 9cbddbd

26 files changed

Lines changed: 343 additions & 93 deletions

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<794be726d31bf395558bb987d94c3205>>
7+
* @generated SignedSource<<56c989556810840e2dd2a42b66d431dc>>
88
*/
99

1010
/**
@@ -288,6 +288,12 @@ public object ReactNativeFeatureFlags {
288288
@JvmStatic
289289
public fun enablePropsUpdateReconciliationAndroid(): Boolean = accessor.enablePropsUpdateReconciliationAndroid()
290290

291+
/**
292+
* When enabled, RuntimeScheduler_Modern clears pending tasks and rendering updates before handling an error.
293+
*/
294+
@JvmStatic
295+
public fun enableRuntimeSchedulerQueueClearingOnError(): Boolean = accessor.enableRuntimeSchedulerQueueClearingOnError()
296+
291297
/**
292298
* Gates a defensive guard around Scheduler::uiManagerDidDispatchCommand and uiManagerDidFinishTransaction that prevents queued rendering-update lambdas from dereferencing the SchedulerDelegate after it has been destroyed (use-after-free).
293299
*/

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<e91fab99f355307aac38de7a5c84e8dd>>
7+
* @generated SignedSource<<43aa532756b07f0b754cd74eb4811664>>
88
*/
99

1010
/**
@@ -63,6 +63,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
6363
private var enableNetworkEventReportingCache: Boolean? = null
6464
private var enablePreparedTextLayoutCache: Boolean? = null
6565
private var enablePropsUpdateReconciliationAndroidCache: Boolean? = null
66+
private var enableRuntimeSchedulerQueueClearingOnErrorCache: Boolean? = null
6667
private var enableSchedulerDelegateInvalidationCache: Boolean? = null
6768
private var enableSwiftUIBasedFiltersCache: Boolean? = null
6869
private var enableViewCullingCache: Boolean? = null
@@ -499,6 +500,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
499500
return cached
500501
}
501502

503+
override fun enableRuntimeSchedulerQueueClearingOnError(): Boolean {
504+
var cached = enableRuntimeSchedulerQueueClearingOnErrorCache
505+
if (cached == null) {
506+
cached = ReactNativeFeatureFlagsCxxInterop.enableRuntimeSchedulerQueueClearingOnError()
507+
enableRuntimeSchedulerQueueClearingOnErrorCache = cached
508+
}
509+
return cached
510+
}
511+
502512
override fun enableSchedulerDelegateInvalidation(): Boolean {
503513
var cached = enableSchedulerDelegateInvalidationCache
504514
if (cached == null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<9d1f725d5a1348a2b31ad4ea2242529c>>
7+
* @generated SignedSource<<5cb98793989e603846a2008aa1a6af41>>
88
*/
99

1010
/**
@@ -114,6 +114,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
114114

115115
@DoNotStrip @JvmStatic public external fun enablePropsUpdateReconciliationAndroid(): Boolean
116116

117+
@DoNotStrip @JvmStatic public external fun enableRuntimeSchedulerQueueClearingOnError(): Boolean
118+
117119
@DoNotStrip @JvmStatic public external fun enableSchedulerDelegateInvalidation(): Boolean
118120

119121
@DoNotStrip @JvmStatic public external fun enableSwiftUIBasedFilters(): Boolean

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<f63cf074bb6687c479e2f4059662ff76>>
7+
* @generated SignedSource<<f4b6d9ed2f6ccff6ab01e53f6048423c>>
88
*/
99

1010
/**
@@ -109,6 +109,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
109109

110110
override fun enablePropsUpdateReconciliationAndroid(): Boolean = false
111111

112+
override fun enableRuntimeSchedulerQueueClearingOnError(): Boolean = false
113+
112114
override fun enableSchedulerDelegateInvalidation(): Boolean = false
113115

114116
override fun enableSwiftUIBasedFilters(): Boolean = false

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<27e88ec53841585796515db0406909dd>>
7+
* @generated SignedSource<<6ee1cc911c3ebb12b31151441dd43605>>
88
*/
99

1010
/**
@@ -67,6 +67,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
6767
private var enableNetworkEventReportingCache: Boolean? = null
6868
private var enablePreparedTextLayoutCache: Boolean? = null
6969
private var enablePropsUpdateReconciliationAndroidCache: Boolean? = null
70+
private var enableRuntimeSchedulerQueueClearingOnErrorCache: Boolean? = null
7071
private var enableSchedulerDelegateInvalidationCache: Boolean? = null
7172
private var enableSwiftUIBasedFiltersCache: Boolean? = null
7273
private var enableViewCullingCache: Boolean? = null
@@ -546,6 +547,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
546547
return cached
547548
}
548549

550+
override fun enableRuntimeSchedulerQueueClearingOnError(): Boolean {
551+
var cached = enableRuntimeSchedulerQueueClearingOnErrorCache
552+
if (cached == null) {
553+
cached = currentProvider.enableRuntimeSchedulerQueueClearingOnError()
554+
accessedFeatureFlags.add("enableRuntimeSchedulerQueueClearingOnError")
555+
enableRuntimeSchedulerQueueClearingOnErrorCache = cached
556+
}
557+
return cached
558+
}
559+
549560
override fun enableSchedulerDelegateInvalidation(): Boolean {
550561
var cached = enableSchedulerDelegateInvalidationCache
551562
if (cached == null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsOverrides_RNOSS_Experimental_Android.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<dcf277b9f00976b0e40394d1e0bd053f>>
7+
* @generated SignedSource<<c481d046dea2f8c8ca77b70d41f86430>>
88
*/
99

1010
/**
@@ -25,6 +25,8 @@ public open class ReactNativeFeatureFlagsOverrides_RNOSS_Experimental_Android :
2525

2626
override fun cxxNativeAnimatedEnabled(): Boolean = true
2727

28+
override fun enableRuntimeSchedulerQueueClearingOnError(): Boolean = true
29+
2830
override fun enableSchedulerDelegateInvalidation(): Boolean = true
2931

3032
override fun preventShadowTreeCommitExhaustion(): Boolean = true

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<5670b927124074a4c59b692de8599cd5>>
7+
* @generated SignedSource<<9945400608426bf3aa1163b9f212d07c>>
88
*/
99

1010
/**
@@ -109,6 +109,8 @@ public interface ReactNativeFeatureFlagsProvider {
109109

110110
@DoNotStrip public fun enablePropsUpdateReconciliationAndroid(): Boolean
111111

112+
@DoNotStrip public fun enableRuntimeSchedulerQueueClearingOnError(): Boolean
113+
112114
@DoNotStrip public fun enableSchedulerDelegateInvalidation(): Boolean
113115

114116
@DoNotStrip public fun enableSwiftUIBasedFilters(): Boolean

packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<52bf46b50e91dacdac8d43c4c00ea6f3>>
7+
* @generated SignedSource<<50f384f98360c4fc9d16d7c25b82aec6>>
88
*/
99

1010
/**
@@ -297,6 +297,12 @@ class ReactNativeFeatureFlagsJavaProvider
297297
return method(javaProvider_);
298298
}
299299

300+
bool enableRuntimeSchedulerQueueClearingOnError() override {
301+
static const auto method =
302+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableRuntimeSchedulerQueueClearingOnError");
303+
return method(javaProvider_);
304+
}
305+
300306
bool enableSchedulerDelegateInvalidation() override {
301307
static const auto method =
302308
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableSchedulerDelegateInvalidation");
@@ -804,6 +810,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enablePropsUpdateReconciliationAndroid(
804810
return ReactNativeFeatureFlags::enablePropsUpdateReconciliationAndroid();
805811
}
806812

813+
bool JReactNativeFeatureFlagsCxxInterop::enableRuntimeSchedulerQueueClearingOnError(
814+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
815+
return ReactNativeFeatureFlags::enableRuntimeSchedulerQueueClearingOnError();
816+
}
817+
807818
bool JReactNativeFeatureFlagsCxxInterop::enableSchedulerDelegateInvalidation(
808819
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
809820
return ReactNativeFeatureFlags::enableSchedulerDelegateInvalidation();
@@ -1204,6 +1215,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
12041215
makeNativeMethod(
12051216
"enablePropsUpdateReconciliationAndroid",
12061217
JReactNativeFeatureFlagsCxxInterop::enablePropsUpdateReconciliationAndroid),
1218+
makeNativeMethod(
1219+
"enableRuntimeSchedulerQueueClearingOnError",
1220+
JReactNativeFeatureFlagsCxxInterop::enableRuntimeSchedulerQueueClearingOnError),
12071221
makeNativeMethod(
12081222
"enableSchedulerDelegateInvalidation",
12091223
JReactNativeFeatureFlagsCxxInterop::enableSchedulerDelegateInvalidation),

packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<f43b6cb2603f2c6dd2da415c4edc0a64>>
7+
* @generated SignedSource<<7a73667c552251d722f6c9800f53d251>>
88
*/
99

1010
/**
@@ -159,6 +159,9 @@ class JReactNativeFeatureFlagsCxxInterop
159159
static bool enablePropsUpdateReconciliationAndroid(
160160
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
161161

162+
static bool enableRuntimeSchedulerQueueClearingOnError(
163+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
164+
162165
static bool enableSchedulerDelegateInvalidation(
163166
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
164167

packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<19a0fa951fda8419542fe2fc376c40f9>>
7+
* @generated SignedSource<<8233ac72d584e038a6c1d94bea37ea40>>
88
*/
99

1010
/**
@@ -198,6 +198,10 @@ bool ReactNativeFeatureFlags::enablePropsUpdateReconciliationAndroid() {
198198
return getAccessor().enablePropsUpdateReconciliationAndroid();
199199
}
200200

201+
bool ReactNativeFeatureFlags::enableRuntimeSchedulerQueueClearingOnError() {
202+
return getAccessor().enableRuntimeSchedulerQueueClearingOnError();
203+
}
204+
201205
bool ReactNativeFeatureFlags::enableSchedulerDelegateInvalidation() {
202206
return getAccessor().enableSchedulerDelegateInvalidation();
203207
}

0 commit comments

Comments
 (0)