From effb64f3cfdcfa2683b5690a8ae5b637e4e3932e Mon Sep 17 00:00:00 2001 From: ViniciusCestarii Date: Tue, 9 Jun 2026 17:44:30 -0300 Subject: [PATCH] proxy-types: prevent race condition when reading client.m_context.connection --- include/mp/proxy-types.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/mp/proxy-types.h b/include/mp/proxy-types.h index 5adab96f..b4885d49 100644 --- a/include/mp/proxy-types.h +++ b/include/mp/proxy-types.h @@ -655,7 +655,14 @@ struct CapRequestTraits<::capnp::Request<_Params, _Results>> template void clientDestroy(Client& client) { - if (client.m_context.connection) { + // Lock because m_context.connection can be cleared concurrently by the + // disconnect cleanup callback (see addSyncCleanup on ProxyClientBase constructor). + bool connected; + { + Lock lock{client.m_context.loop->m_mutex}; + connected = client.m_context.connection != nullptr; + } + if (connected) { MP_LOG(*client.m_context.loop, Log::Debug) << "IPC client destroy " << CxxTypeName(client); } else { KJ_LOG(INFO, "IPC interrupted client destroy", CxxTypeName(client));