Merge pull request #4803 from filecoin-project/fix/paych-mgr-ctx-cancel-race
Fix race in paych manager when req context is cancelled
This commit is contained in:
commit
d1e4211f4b
@ -36,8 +36,6 @@ type fundsReq struct {
|
|||||||
lk sync.Mutex
|
lk sync.Mutex
|
||||||
// merge parent, if this req is part of a merge
|
// merge parent, if this req is part of a merge
|
||||||
merge *mergedFundsReq
|
merge *mergedFundsReq
|
||||||
// whether the req's context has been cancelled
|
|
||||||
active bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFundsReq(ctx context.Context, amt types.BigInt) *fundsReq {
|
func newFundsReq(ctx context.Context, amt types.BigInt) *fundsReq {
|
||||||
@ -46,7 +44,6 @@ func newFundsReq(ctx context.Context, amt types.BigInt) *fundsReq {
|
|||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
promise: promise,
|
promise: promise,
|
||||||
amt: amt,
|
amt: amt,
|
||||||
active: true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,25 +58,18 @@ func (r *fundsReq) onComplete(res *paychFundsRes) {
|
|||||||
// cancel is called when the req's context is cancelled
|
// cancel is called when the req's context is cancelled
|
||||||
func (r *fundsReq) cancel() {
|
func (r *fundsReq) cancel() {
|
||||||
r.lk.Lock()
|
r.lk.Lock()
|
||||||
|
defer r.lk.Unlock()
|
||||||
r.active = false
|
|
||||||
m := r.merge
|
|
||||||
|
|
||||||
r.lk.Unlock()
|
|
||||||
|
|
||||||
// If there's a merge parent, tell the merge parent to check if it has any
|
// If there's a merge parent, tell the merge parent to check if it has any
|
||||||
// active reqs left
|
// active reqs left
|
||||||
if m != nil {
|
if r.merge != nil {
|
||||||
m.checkActive()
|
r.merge.checkActive()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// isActive indicates whether the req's context has been cancelled
|
// isActive indicates whether the req's context has been cancelled
|
||||||
func (r *fundsReq) isActive() bool {
|
func (r *fundsReq) isActive() bool {
|
||||||
r.lk.Lock()
|
return r.ctx.Err() == nil
|
||||||
defer r.lk.Unlock()
|
|
||||||
|
|
||||||
return r.active
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// setMergeParent sets the merge that this req is part of
|
// setMergeParent sets the merge that this req is part of
|
||||||
|
Loading…
Reference in New Issue
Block a user