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
This commit is contained in:
Kevin Gozali authored and meta-codesync[bot] committed 2026-04-20 12:30:34 -07:00
1 parent 3fb1fea57e
commit 786ebf0cac
1 file changed
+10
@@ -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;