From 786ebf0cac806a5dbf18520d8422e12c4594d910 Mon Sep 17 00:00:00 2001 From: Kevin Gozali Date: Mon, 20 Apr 2026 12:30:34 -0700 Subject: [PATCH] Guard Tracing.end handler against missing Tracing.start in jsinspector-modern (#56496) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56496 Add a guard in the `Tracing.end` CDP handler to check `sessionState_.hasPendingTraceRecording` before calling `stopTracing()`. This prevents a null-pointer crash (SIGSEGV) in `HostTargetTraceRecording::stop()` when `Tracing.end` is sent after `Tracing.start` was rejected (e.g. due to multiple registered host targets in the global inspector singleton). The guard matches the existing pattern in `TracingAgent::~TracingAgent()` (line 29). When tracing was never started, it now returns an `InvalidRequest` error instead of crashing. Changelog: [Internal] Reviewed By: huntie Differential Revision: D101557975 fbshipit-source-id: 3ab754b9421b3bee3e3bde99ce012007d5a10368 --- .../ReactCommon/jsinspector-modern/TracingAgent.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp b/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp index d20203d0e88..2ac6f667963 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp @@ -90,6 +90,16 @@ bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) { return true; } else if (req.method == "Tracing.end") { + if (!sessionState_.hasPendingTraceRecording) { + frontendChannel_( + cdp::jsonError( + req.id, + cdp::ErrorCode::InvalidRequest, + "Tracing has not been started")); + + return true; + } + auto tracingProfile = hostTargetController_.stopTracing(); sessionState_.hasPendingTraceRecording = false;