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

rpcserver: fix recoveryPending attribute #355

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1148,12 +1148,19 @@ func (s *rpcServer) RecoverAccounts(ctx context.Context,

s.recoveryMutex.Lock()
if s.recoveryPending {
defer s.recoveryMutex.Unlock()
s.recoveryMutex.Unlock()
Copy link
Member

Choose a reason for hiding this comment

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

nit: alternatively we could just use an atomic int to avoid the (slightly complex) locking logic.

return nil, fmt.Errorf("recovery already in progress")
}
s.recoveryPending = true
s.recoveryMutex.Unlock()

// Mark the recovery process as done whenever we finish.
Copy link
Member

Choose a reason for hiding this comment

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

Should we move this whole block just one line down, so it's after the Unlock()? That way it's a bit easier to reason about whether this could lead to a deadlock or not (in case you miss the defer when scanning the code linearly).

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, my comment was a bit inaccurate. But the s.recoveryPending = true should still be within the lock.

defer func() {
s.recoveryMutex.Lock()
s.recoveryPending = false
s.recoveryMutex.Unlock()
}()

log.Infof("Attempting to recover accounts...")

var recoveredAccounts []*account.Account
Expand Down Expand Up @@ -1188,10 +1195,6 @@ func (s *rpcServer) RecoverAccounts(ctx context.Context,
}
}

s.recoveryMutex.Lock()
s.recoveryPending = false
s.recoveryMutex.Unlock()

return &poolrpc.RecoverAccountsResponse{
NumRecoveredAccounts: uint32(numRecovered),
}, nil
Expand Down