This bug is currently causing mptest “disconnecting and blocking” test to occasionally hang as reported by maflcko in https://github.com/bitcoin/bitcoin/issues/33244.
The bug was actually first reported by Sjors in https://github.com/Sjors/bitcoin/pull/90#issuecomment-3024942087 and there are more details about it in #189.
The bug is caused by the “disconnecting and blocking” test triggering a disconnect right before a server IPC call returns. This results in a race between the IPC server thread and the onDisconnect handler in the event loop thread both trying to destroy the server’s request_threads ProxyClient<Thread> object when the IPC call is done.
There was a lack of synchronization in this case, fixed here by adding loop->sync() various places. There were also lock order issues where Waiter::m_mutex could be incorrectly locked before EventLoop::m_mutex resulting in a deadlock.