Skip to content

Add ProxyClientBase destroy_connection option #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2019

Conversation

ryanofsky
Copy link
Collaborator

Give ProxyClientBase class the ability to delete the Connection object in its destructor. This avoids the need for separate ShutdownLoop close hook in bitcoin/bitcoin#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.

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 bitcoin/bitcoin#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.
@ryanofsky ryanofsky merged commit c685fa9 into bitcoin-core:master Aug 6, 2019
ryanofsky added a commit that referenced this pull request Aug 6, 2019
c685fa9 Add ProxyClientBase destroy_connection option (Russell Yanofsky)

Pull request description:

  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 bitcoin/bitcoin#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.

Top commit has no ACKs.

Tree-SHA512: eee8d3e326f2530703954c6c0d963852886117614190de8aaa681982bb2e10f50473577118600103cbdf2061ec31417064c158e57e15843a25e37a8bf25eb485
@bitcoin-core bitcoin-core locked and limited conversation to collaborators Jun 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant