Add ProxyClientBase destroy_connection option #7

pull ryanofsky wants to merge 1 commits into bitcoin-core:master from ryanofsky:pr/destroyconn changing 4 files +67 −36
  1. ryanofsky commented at 5:50 PM on August 6, 2019: collaborator

    Give ProxyClientBase class the ability to delete the Connection object in its destructor. This avoids the need for separate ShutdownLoop close hook in https://github.com/bitcoin/bitcoin/pull/10102.

    This exposed a race condition which required adding a TaskSet member to Connection objects to fix. With the previous ShutdownLoop approach, the client capability handle would be freed in the event loop thread, then there would be a switch back to the client thread, then there would be another switch back to the event loop thread to free the connection, most likely after the event loop thread had a chance to process new events. With the new approach, the client capability handle and Connection object are destroyed back to back in the event loop thread, causing the onDisconnect handler to fire when it previously didn't, after the Connection object had already been destroyed, and resulting in a double deletion of the Connection pointer. The race is fixed here by using separate kj::TaskSet objects for each connection, so onDisconnect events are now cancelled as Connection objects are destroyed.

  2. Add ProxyClientBase destroy_connection option
    Give ProxyClientBase class the ability to delete the Connection object in its
    destructor. This avoids the need for separate
    [`ShutdownLoop`](https://github.com/ryanofsky/bitcoin/blob/pr/ipc/src/interfaces/capnp/ipc.cpp#L50-L65)
    close hook in https://github.com/bitcoin/bitcoin/pull/10102.
    
    This exposed a race condition which required adding a TaskSet member to
    Connection objects to fix. With the previous ShutdownLoop approach, the client
    capability handle would be freed in the event loop thread, then there would be
    a switch back to the client thread, then there would be another switch back to
    the event loop thread to free the connection, most likely after the event loop
    thread had a chance to process new events. With the new approach, the client
    capability handle and Connection object are destroyed back to back in the event
    loop thread, causing the onDisconnect handler to fire when it previously
    didn't, after the Connection object had already been destroyed, and resulting
    in a double deletion of the Connection pointer. The race is fixed here by using
    separate kj::TaskSet objects for each connection, so onDisconnect events are
    now cancelled as Connection objects are destroyed.
    c685fa9bed
  3. ryanofsky merged this on Aug 6, 2019
  4. ryanofsky closed this on Aug 6, 2019

  5. ryanofsky referenced this in commit 8125688f6c on Aug 6, 2019
  6. bitcoin-core locked this on Jun 25, 2025

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/libmultiprocess. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-18 10:30 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me