Skip to content
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

ASAN leak when exiting node #2360

Merged
merged 1 commit into from
Oct 22, 2019

Conversation

wezrule
Copy link
Contributor

@wezrule wezrule commented Oct 22, 2019

The following ASAN output was generated with the node.peers test, but it's not specific to this test, just seems to be easily reproducible there. Found on Ubuntu 18.04 with Clang, couldn't reproduce on MacOS:
https://gist.github.com/wezrule/17cb9b81ceeaf1a5ccfcec900f666b82

Was a bit of a bugger to locate as anything could have been causing it, but I knew the node destructor was not being called so something must have been holding a shared_ptr reference to it, but wasn't sure what. I ended up rolling back commits to find the culprit, which ended up being #1264. In particular (for this example at least) it was this callback:

node_l->worker.push_task ([node_l]() {
    node_l->ongoing_peer_store ();
});

The worker::stop function is called but it doesn't remove the callbacks that have been added. So it maintains this node reference. And because class node has a reference to the worker, they end up keeping each other alive when the test is finished. Passing in a weak_ptr of the node solves this issue and is what we do in a lot of places in our code but not all. To have a "catch all" I'm removing all the callbacks when the worker is stopped and preventing other ones being added which can happen in other threads.

@wezrule wezrule added the sanitizers Related to thread, address or undefined sanitizers label Oct 22, 2019
@wezrule wezrule added this to the V20.0 milestone Oct 22, 2019
@wezrule wezrule requested a review from cryptocode October 22, 2019 16:53
@wezrule wezrule self-assigned this Oct 22, 2019
Copy link
Contributor

@cryptocode cryptocode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wezrule wezrule merged commit a751f85 into nanocurrency:master Oct 22, 2019
@wezrule wezrule deleted the asan_leak_node_peers_test branch October 22, 2019 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sanitizers Related to thread, address or undefined sanitizers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants