From 68a760a273aa8daee721c95b03141991800a3b1e Mon Sep 17 00:00:00 2001 From: Ryan Zuklie Date: Thu, 17 Oct 2024 08:15:06 -0700 Subject: [PATCH] Disable perfetto lock for OnSetup/OnStart/OnStart. This lock causes a deadlock in the handler where OnStop is holding it waiting for the poller to complete, but the poller is waiting for the lock in GetDataSourceLocked. As a result Write can be called concurrent to OnStart/OnStop, but not OnSetup (guaranteed by Perfetto). The state Write reads is const from OnSetup onwards, so is fine to read without a lock. Bug: 320700806 Test: atest libnetworkstats_test Change-Id: I2a8390268aa8f55c617c22e48129b5cb6fbaf673 --- .../libnetworkstats/include/netdbpf/NetworkTraceHandler.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/service-t/native/libs/libnetworkstats/include/netdbpf/NetworkTraceHandler.h b/service-t/native/libs/libnetworkstats/include/netdbpf/NetworkTraceHandler.h index 6bf186aa63..dd6ed2e056 100644 --- a/service-t/native/libs/libnetworkstats/include/netdbpf/NetworkTraceHandler.h +++ b/service-t/native/libs/libnetworkstats/include/netdbpf/NetworkTraceHandler.h @@ -88,6 +88,13 @@ class NetworkTraceHandler // Connects to the system Perfetto daemon and registers the trace handler. static void InitPerfettoTracing(); + // This prevents Perfetto from holding the data source lock when calling + // OnSetup, OnStart, or OnStop. The lock is still held by the LockedHandle + // returned by GetDataSourceLocked. Disabling this lock prevents a deadlock + // where OnStop holds this lock waiting for the poller to stop, but the poller + // is running the callback that is trying to acquire the lock. + static constexpr bool kRequiresCallbacksUnderLock = false; + // When isTest is true, skip non-hermetic code. NetworkTraceHandler(bool isTest = false) : mIsTest(isTest) {}