@@ -103,25 +103,27 @@ auto PassField(Priority<1>, TypeList<>, ServerContext& server_context, const Fn&
103103 // recursive call (IPC call calling back to the caller which
104104 // makes another IPC call), so avoid modifying the map.
105105 const bool erase_thread{inserted};
106- KJ_DEFER (if (erase_thread) {
107- // Erase the request_threads entry on the event loop
108- // thread with loop->sync(), so if the connection is
109- // broken there is not a race between this thread and
110- // the disconnect handler trying to destroy the thread
111- // client object.
112- server.m_context .loop ->sync ([&] {
113- // Look up the thread again without using existing
114- // iterator since entry may no longer be there after
115- // a disconnect. Destroy node after releasing
116- // Waiter::m_mutex, so the ProxyClient<Thread>
117- // destructor is able to use EventLoop::mutex
118- // without violating lock order.
119- ConnThreads::node_type removed;
120- {
121- std::unique_lock<std::mutex> lock (thread_context.waiter ->m_mutex );
122- removed = request_threads.extract (server.m_context .connection );
123- }
124- });
106+ [[maybe_unused]] const auto _cleanup = kj::defer ([&] {
107+ if (erase_thread) {
108+ // Erase the request_threads entry on the event loop
109+ // thread with loop->sync(), so if the connection is
110+ // broken there is not a race between this thread and
111+ // the disconnect handler trying to destroy the thread
112+ // client object.
113+ server.m_context .loop ->sync ([&] {
114+ // Look up the thread again without using existing
115+ // iterator since entry may no longer be there after
116+ // a disconnect. Destroy node after releasing
117+ // Waiter::m_mutex, so the ProxyClient<Thread>
118+ // destructor is able to use EventLoop::mutex
119+ // without violating lock order.
120+ ConnThreads::node_type removed;
121+ {
122+ std::unique_lock<std::mutex> lock (thread_context.waiter ->m_mutex );
123+ removed = request_threads.extract (server.m_context .connection );
124+ }
125+ });
126+ }
125127 });
126128 fn.invoke (server_context, args...);
127129 }
0 commit comments