Merge pull request #8829 from zl03jsj/fix/TestPaychGetRestartAfterAddFundsMsg_may_stuck_in_forever_waiting

Fix: PaychGetRestartAfterAddFundsMsg may stuck in forever waiting
This commit is contained in:
Łukasz Magiera 2022-06-09 15:30:22 +02:00 committed by GitHub
commit 1190050e86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 4 deletions

View File

@ -87,6 +87,7 @@ func newManager(pchstore *Store, pchapi managerAPI) (*Manager, error) {
channels: make(map[string]*channelAccessor), channels: make(map[string]*channelAccessor),
pchapi: pchapi, pchapi: pchapi,
} }
pm.ctx, pm.shutdown = context.WithCancel(context.Background())
return pm, pm.Start() return pm, pm.Start()
} }

View File

@ -136,7 +136,7 @@ func newMockPaychAPI() *mockPaychAPI {
func (pchapi *mockPaychAPI) StateWaitMsg(ctx context.Context, mcid cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*api.MsgLookup, error) { func (pchapi *mockPaychAPI) StateWaitMsg(ctx context.Context, mcid cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*api.MsgLookup, error) {
pchapi.lk.Lock() pchapi.lk.Lock()
response := make(chan types.MessageReceipt) response := make(chan types.MessageReceipt, 1)
if response, ok := pchapi.waitingResponses[mcid]; ok { if response, ok := pchapi.waitingResponses[mcid]; ok {
defer pchapi.lk.Unlock() defer pchapi.lk.Unlock()
@ -151,8 +151,12 @@ func (pchapi *mockPaychAPI) StateWaitMsg(ctx context.Context, mcid cid.Cid, conf
pchapi.waitingCalls[mcid] = &waitingCall{response: response} pchapi.waitingCalls[mcid] = &waitingCall{response: response}
pchapi.lk.Unlock() pchapi.lk.Unlock()
receipt := <-response select {
return &api.MsgLookup{Receipt: receipt}, nil case receipt := <-response:
return &api.MsgLookup{Receipt: receipt}, nil
case <-ctx.Done():
return nil, ctx.Err()
}
} }
func (pchapi *mockPaychAPI) receiveMsgResponse(mcid cid.Cid, receipt types.MessageReceipt) { func (pchapi *mockPaychAPI) receiveMsgResponse(mcid cid.Cid, receipt types.MessageReceipt) {

View File

@ -631,7 +631,7 @@ func TestPaychGetRestartAfterAddFundsMsg(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
// Simulate shutting down system // Simulate shutting down system
mock.close() require.NoError(t, mgr.Stop())
// Create a new manager with the same datastore // Create a new manager with the same datastore
mock2 := newMockManagerAPI() mock2 := newMockManagerAPI()

View File

@ -3,6 +3,7 @@ package paychmgr
import ( import (
"bytes" "bytes"
"context" "context"
"errors"
"fmt" "fmt"
"sort" "sort"
"sync" "sync"
@ -351,6 +352,11 @@ func (ca *channelAccessor) queueSize() int {
// msgWaitComplete is called when the message for a previous task is confirmed // msgWaitComplete is called when the message for a previous task is confirmed
// or there is an error. // or there is an error.
func (ca *channelAccessor) msgWaitComplete(ctx context.Context, mcid cid.Cid, err error) { func (ca *channelAccessor) msgWaitComplete(ctx context.Context, mcid cid.Cid, err error) {
// if context is canceled, should Not mark message to 'bad', just return.
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
return
}
ca.lk.Lock() ca.lk.Lock()
defer ca.lk.Unlock() defer ca.lk.Unlock()