From 777dce5e08c6a78f047e65adccb2f9d8f3cf7db7 Mon Sep 17 00:00:00 2001 From: positiveblue Date: Mon, 11 Apr 2022 15:29:21 -0700 Subject: [PATCH] rpcserver: update `recoveryPending` attribute The rpcserver cannot have more than one account recovery process running at once. The server uses a internal attribute (`recoveryPending`) that is set to true when a new recovery process starts. However, that attribute was only set to false if the process ended successfully, leaving the server unable to try more recoveries after a failure. --- rpcserver.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 594986130..c229ee82b 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1148,12 +1148,19 @@ func (s *rpcServer) RecoverAccounts(ctx context.Context, s.recoveryMutex.Lock() if s.recoveryPending { - defer s.recoveryMutex.Unlock() + s.recoveryMutex.Unlock() return nil, fmt.Errorf("recovery already in progress") } s.recoveryPending = true s.recoveryMutex.Unlock() + // Mark the recovery process as done whenever we finish. + defer func() { + s.recoveryMutex.Lock() + s.recoveryPending = false + s.recoveryMutex.Unlock() + }() + log.Infof("Attempting to recover accounts...") var recoveredAccounts []*account.Account @@ -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