Skip to content

Conversation

bvbfan
Copy link
Contributor

@bvbfan bvbfan commented Mar 15, 2020

This pull request fully replace #18279 it fix 3 issues with wallet

  1. Crash in wallet destructor while it tries to delete mutex while it's hold by notification thread
  2. Crash in notification disconnect due to notification callback is set to nullptr before unregister interface is done
  3. Ensure unregister interface has no more background callbacks before returning to notification disconnect

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 15, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@bvbfan
Copy link
Contributor Author

bvbfan commented Mar 16, 2020

Simplify patch, make more fuzzing test

#!/bin/bash
while [ 1 ]
do
    src/bitcoin-cli -testnet loadwallet test
    src/bitcoin-cli -testnet unloadwallet test3
    src/bitcoin-cli -testnet loadwallet test2
    src/bitcoin-cli -testnet unloadwallet test
    src/bitcoin-cli -testnet loadwallet test3
    src/bitcoin-cli -testnet unloadwallet test2
done

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

#18338 may still have some issues, but I think it is probably a better approach and I would suggest abandoning this.

@bvbfan
Copy link
Contributor Author

bvbfan commented Mar 17, 2020

Use future instead of raw loop for waiting pending callbacks. It still much matters to me compared to #18338

@DrahtBot DrahtBot mentioned this pull request Mar 20, 2020
Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

Approach NACK. The problem is not in the scheduler, but in the invalid assumption that it's safe to delete a CValidationInterface instance right after UnregisterValidationInterface - it's wrong because of boost::signals2 threading model.

@bvbfan
Copy link
Contributor Author

bvbfan commented Mar 24, 2020

@promag same as your approach with more aggressive refactor + missing virtual desctructors.

@bvbfan bvbfan changed the title Protect wallet from scheduler race conditions. Protect wallet from by using shared pointer Mar 24, 2020
@bvbfan bvbfan changed the title Protect wallet from by using shared pointer Protect wallet by using shared pointers Mar 24, 2020
@ryanofsky
Copy link
Contributor

Concept ACK, though this is making a lot of changes in a single commit. The changes will probably get simpler if #18338 is merged first, and maybe they can be broken up into smaller commits. Could consider rebasing on top of #18338 of you don't want to wait for it to be merged. I'd also encourage you to review #18338!

@ryanofsky
Copy link
Contributor

ryanofsky commented Mar 25, 2020

Oh, just saw this PR has expanded since I looked at it previously. I think some of the uses of shared_ptr / weak_ptr here like the new ones added in CWalletTx do not make sense. shared_ptr / weak_ptr only make sense when lifetime of the reference doesn't have a definite scope. For cases like CWalletTx where the wallet reference can't outlive the wallet, CWallet& makes more sense than weak_ptr<CWallet>. (Also, though in that specific case, it would be preferable to stop storing the wallet references entirely since they are redundant and no CWalletTx method is ever called without already having a reference to the wallet).

It would probably make sense to break this PR up into multiple commits so individual changes here can be understood and reviewed more easily

@bvbfan
Copy link
Contributor Author

bvbfan commented Mar 25, 2020

shared_ptr / weak_ptr only make sense when lifetime of the reference doesn't have a definite scope.

I agree, in plus it defines no ownership. I agree, that reference makes much more sense here, too

@promag
Copy link
Contributor

promag commented Oct 6, 2020

Is this still a bug fix? Do you think you can split in multiple commits?

@bvbfan
Copy link
Contributor Author

bvbfan commented Oct 7, 2020

Hi @promag mostly it's not an issue, AFAIK. It has some side effects in Qt gui, it was fixed i think. Notification proxy can extend notification lifetime which isn't correct to me. As well as using shared pointers only to validation interface, missing virtual destructors to interface classes like NetEventsInterface (it's not a problem since it's not deleted through base pointer till now).
I can split it to more commits if you're interested in this features.

bvbfan added 3 commits October 7, 2020 15:28
Signed-off-by: Anthony Fieroni <bvbfan@abv.bg>
Signed-off-by: Anthony Fieroni <bvbfan@abv.bg>
Signed-off-by: Anthony Fieroni <bvbfan@abv.bg>
@bvbfan
Copy link
Contributor Author

bvbfan commented Oct 7, 2020

Refactor pwallet to wallet (wallet* to wallet shared_ptr) is removed.

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 1, 2020

🐙 This pull request conflicts with the target branch and needs rebase.

Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".

@maflcko
Copy link
Member

maflcko commented Oct 22, 2021

Needs rebase if still relevant

@bvbfan
Copy link
Contributor Author

bvbfan commented Oct 22, 2021

I will investigate if it still needed, actually @ryanofsky does excellent work to well define shared interfaces ownership.

@DrahtBot
Copy link
Contributor

There hasn't been much activity lately and the patch still needs rebase. What is the status here?
  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

@maflcko
Copy link
Member

maflcko commented Feb 22, 2022

Closing for now. Feel free to ask for this to be reopened or create a new pull request.

@maflcko maflcko closed this Feb 22, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Feb 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants