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

blockchain: always relock chainLock for subscription callbacks #2128

Conversation

kcalvinalvin
Copy link
Collaborator

For various b.sendNotifcation() callbacks, if a runtime panic happens, we don't get any useful debugging information since the error that happens first is the "unlock of unlocked mutex" error.

This is because we temporarily unlock the chainLock for callbacks and then relock them. However, since the relocking code is executed after the completion of the callback, if an error happens during that callback, we never relock the chainLock.

Switching to an anonymous function and having the unlock code as a defer will ensure that the lock always relocks.

For various b.sendNotifcation() callbacks, if a runtime panic happens,
we don't get any useful debugging information since the error that
happens first is the "unlock of unlocked mutex" error.

This is because we temporarily unlock the chainLock for callbacks and
then relock them.  However, since the relocking code is executed after
the completion of the callback, if an error happens during that
callback, we never relock the chainLock.

Switching to an anonymous function and having the unlock code as a
defer will ensure that the lock always relocks.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 8060178922

Details

  • 0 of 15 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.007%) to 56.732%

Totals Coverage Status
Change from base Build 8057525961: 0.007%
Covered Lines: 29202
Relevant Lines: 51474

💛 - Coveralls

b.chainLock.Unlock()
b.sendNotification(NTBlockAccepted, block)
b.chainLock.Lock()
func() {
Copy link
Member

Choose a reason for hiding this comment

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

What exactly does the function closure achieve here? Can't we just do the plain defer?

Copy link
Member

Choose a reason for hiding this comment

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

Is it attempting to rely on defer order execution after a panic?

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM ✈️

@Roasbeef Roasbeef merged commit f0ec9fb into btcsuite:master Mar 9, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants