Add ProxyClientBase destroy_connection option#7
Merged
ryanofsky merged 1 commit intobitcoin-core:masterfrom Aug 6, 2019
Merged
Add ProxyClientBase destroy_connection option#7ryanofsky merged 1 commit intobitcoin-core:masterfrom
ryanofsky merged 1 commit intobitcoin-core:masterfrom
Conversation
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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Give ProxyClientBase class the ability to delete the Connection object in its destructor. This avoids the need for separate
ShutdownLoopclose 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.