Skip to content

Commit d4eab46

Browse files
fkgozalifacebook-github-bot
authored andcommitted
Guard Tracing.end handler against missing Tracing.start in jsinspector-modern
Summary: 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] Differential Revision: D101557975
1 parent 5620b1b commit d4eab46

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) {
9090

9191
return true;
9292
} else if (req.method == "Tracing.end") {
93+
if (!sessionState_.hasPendingTraceRecording) {
94+
frontendChannel_(
95+
cdp::jsonError(
96+
req.id,
97+
cdp::ErrorCode::InvalidRequest,
98+
"Tracing has not been started"));
99+
100+
return true;
101+
}
102+
93103
auto tracingProfile = hostTargetController_.stopTracing();
94104

95105
sessionState_.hasPendingTraceRecording = false;

0 commit comments

Comments
 (0)