Skip to content

Commit 786ebf0

Browse files
fkgozalimeta-codesync[bot]
authored andcommitted
Guard Tracing.end handler against missing Tracing.start in jsinspector-modern (#56496)
Summary: Pull Request resolved: #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
1 parent 3fb1fea commit 786ebf0

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)