Note: This is based on #361. Initial commits should be reviewed in that PR.
Add Connection class disconnect and waitDrained methods (waitDrained is reached through Connection::tracker()) to provide more flexibility when forcibly disconnecting from remote clients or servers.
Without these methods, the only way to forcibly close IPC connections is to delete Connection objects. This works but is not ideal because once a Connection object is gone, it is difficult to track state still associated with the connection, particularly:
ProxyServerobjects that may still be alive because they are executing asynchronous requests made before the disconnect. Without a way to track these objects, there is no generic way to wait for requests to finish executing after disconnecting. So individual IPC interfaces like the Bitcoin mining interface would need to implement custom synchronization to avoid race conditions during shutdown. Followup PR https://github.com/bitcoin/bitcoin/pull/35932 builds on this PR, calling the newwaitDrainedmethod introduced here to avoid IPC mining crashes on Bitcoin Core shutdown without needing to change the mining code. A unit test is added here simulating these mining crashes.ProxyClientobjects that contain pointers toConnectionobjects. CurrentlyProxyClientobjects need to register cleanup handlers withConnectionobjects to deal with Connections being deleted, which consumes memory and complicatesProxyClientshutdown logic. After this change, a followup PR will drop the cleanup handlers soConnectionobjects no longer need to track lists ofProxyClientobjects associated with them. This is implemented in #336.
Status (2026-11-04)
This waits on review and on its base PR #361, which is also open. It has a Concept ACK and one detailed review whose bug reports moved to #361; both reviewers plan to look again after updates.
- Remaining work:
- Update the code comments and commit message that still refer to
Connection::waitDrained()andConnection::pendingServerObjects(); both are nowServerObjectTrackermethods, reached throughConnection::tracker().
- Update the code comments and commit message that still refer to
- Open questions:
- Whether
waitDrained()should assert thatdisconnect()was called first; the author asked what scenario motivates it: #335 (review) - Feedback that comments and commit messages are too long and read like a story (https://github.com/bitcoin-core/libmultiprocess/pull/335#pullrequestreview-4982982109, #335 (comment)). The 2026-09-11 push revised comments, but there is no direct reply yet.
- Whether
- Promised updates: revisit exception safety in
disconnect()when a cleanup step throws, kept out of this PR's scope for now: #335 (review)