Skip to content

refactor: Skip manual signal disconnection in descructors #607

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

Closed
wants to merge 4 commits into from

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented May 26, 2022

Internally, interfaces::HandlerImpl keeps a member of the boost::signals2::scoped_connection type

boost::signals2::scoped_connection m_connection;
which automatically disconnects on destruction.

Therefore, manual disconnections are redundant in class destructors.

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.

Code review ACK 512072f.

@DrahtBot
Copy link
Contributor

DrahtBot commented May 27, 2022

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #417 (Ditch wallet model juggling by promag)

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.

Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

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

Code review ACK 512072f

To not forget about this, would be nice to add a doc comment at the top of the HandlerImpl class and MakeHandler(boost::signals2::connection) explaining that the returned Handler disconnects the signal when the object is destructed.

Copy link
Member

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

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

ACK 512072f

Confirmed PR description, and compiled and ran locally.

@hebasto
Copy link
Member Author

hebasto commented May 29, 2022

@ryanofsky

Would you mind having a look into this PR?

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.

Tentative code review ACK 512072f. For all the commits except the first commit, the destructors are non-empty, so this PR changes behavior by disconnecting signals after the other code in the destructor instead of before the other code in the constructor. In theory this could be a problem if a new signal is sent while the object is being destroyed. Previously the signal would be ignored, now it could call methods on a half destroyed object.

It would be good if commit messages acknowledged the delayed disconnection of signals, and perhaps explained why it was safe to delay disconnecting signals.

@hebasto
Copy link
Member Author

hebasto commented May 31, 2022

... now it could call methods on a half destroyed object.

During destruction, only one thread has access to the object, right?

@ryanofsky
Copy link
Contributor

... now it could call methods on a half destroyed object.

During destruction, only one thread has access to the object, right?

The lambdas passed to handleNotification methods are capturing [this] so they can reference the object when notifications are sent. That is why it might be important to disconnect the notifications earlier instead of later. But I don't know whether this is important, which is why I raised the question. Also even if notifications were single threaded (I don't think they are) it might still matter if they are disconnected later during destruction instead of earlier, because maybe later code in the destructor could trigger them.

Overall, I would guess this PR is probably safe, I just think it could use a better explanation of how it is safe.

@hebasto
Copy link
Member Author

hebasto commented Jul 19, 2022

Thank all of reviewers for your reviews.

Going to close this PR to do not raise safety concerns.

@hebasto hebasto closed this Jul 19, 2022
@bitcoin-core bitcoin-core locked and limited conversation to collaborators Jul 19, 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