mirror of
https://github.com/status-im/status-go.git
synced 2025-01-21 20:20:29 +00:00
Fix a deadlock when timeout happens while a sign request is being approved.
This commit is contained in:
parent
4cc6028d59
commit
f694a6d52b
@ -114,7 +114,11 @@ func (rs *PendingRequests) Wait(id string, timeout time.Duration) Result {
|
||||
case rst := <-request.result:
|
||||
return rst
|
||||
case <-time.After(timeout):
|
||||
rs.complete(request, EmptyResponse, ErrSignReqTimedOut)
|
||||
_, err := rs.tryLock(request.ID)
|
||||
// if request is not already in progress, we complete it.
|
||||
if err == nil {
|
||||
rs.complete(request, EmptyResponse, ErrSignReqTimedOut)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -209,16 +209,17 @@ func (s PendingRequestsSuite) TestWaitFail() {
|
||||
}
|
||||
|
||||
func (s PendingRequestsSuite) TestWaitTimeout() {
|
||||
req, err := s.pendingRequests.Add(context.Background(), "", nil, s.delayedCompleteFunc())
|
||||
req, err := s.pendingRequests.Add(context.Background(), "", nil, s.defaultCompleteFunc())
|
||||
s.NoError(err)
|
||||
|
||||
s.True(s.pendingRequests.Has(req.ID), "sign request should exist")
|
||||
|
||||
go func() {
|
||||
time.Sleep(10 * time.Microsecond)
|
||||
result := s.pendingRequests.Approve(req.ID, correctPassword, testVerifyFunc)
|
||||
s.NoError(result.Error)
|
||||
s.NotNil(result.Error)
|
||||
}()
|
||||
|
||||
result := s.pendingRequests.Wait(req.ID, 0*time.Second)
|
||||
s.Equal(result.Error, ErrSignReqTimedOut)
|
||||
s.Equal(ErrSignReqTimedOut, result.Error)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user