From 6ab062dfec990ec4915b2ca4514fbddff9bbd9a3 Mon Sep 17 00:00:00 2001 From: Xin Chen Date: Tue, 1 Aug 2023 12:19:17 -0700 Subject: [PATCH] Fix concurrent consumers issue with ReactMarker (#38710) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38710 Fix a race condition when multiple consumers try to access ReactMarker and trigger calls to native module. Even though ReactMarker uses `ConcurrentLinkedQueue`, the loop itself could race and cause NPE. Changelog: [Android][Fixed] - Fix race condition with ReactMarker calls to its native module Reviewed By: rshest Differential Revision: D47933993 fbshipit-source-id: a56e5e4f3564922d534235991da5b6842248bf24 --- .../src/main/java/com/facebook/react/bridge/ReactMarker.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMarker.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMarker.java index ebfd755f8f7029..bf754a14952b6f 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMarker.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMarker.java @@ -193,8 +193,8 @@ private static void notifyNativeMarker(ReactMarkerConstants name, @Nullable Long nativeLogMarker(name.name(), now); // Then send all cached native ReactMarkers - while (!sNativeReactMarkerQueue.isEmpty()) { - ReactMarkerRecord record = sNativeReactMarkerQueue.poll(); + ReactMarkerRecord record; + while ((record = sNativeReactMarkerQueue.poll()) != null) { nativeLogMarker(record.getMarkerName(), record.getMarkerTime()); } } else {