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

Fix race in paych manager when req context is cancelled #4803

Merged
merged 1 commit into from
Nov 11, 2020
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
18 changes: 4 additions & 14 deletions paychmgr/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ type fundsReq struct {
lk sync.Mutex
// merge parent, if this req is part of a merge
merge *mergedFundsReq
// whether the req's context has been cancelled
active bool
}

func newFundsReq(ctx context.Context, amt types.BigInt) *fundsReq {
Expand All @@ -46,7 +44,6 @@ func newFundsReq(ctx context.Context, amt types.BigInt) *fundsReq {
ctx: ctx,
promise: promise,
amt: amt,
active: true,
}
}

Expand All @@ -61,25 +58,18 @@ func (r *fundsReq) onComplete(res *paychFundsRes) {
// cancel is called when the req's context is cancelled
func (r *fundsReq) cancel() {
r.lk.Lock()

r.active = false
m := r.merge

r.lk.Unlock()
defer r.lk.Unlock()

// If there's a merge parent, tell the merge parent to check if it has any
// active reqs left
if m != nil {
m.checkActive()
if r.merge != nil {
r.merge.checkActive()
}
}

// isActive indicates whether the req's context has been cancelled
func (r *fundsReq) isActive() bool {
r.lk.Lock()
defer r.lk.Unlock()

return r.active
return r.ctx.Err() == nil
}

// setMergeParent sets the merge that this req is part of
Expand Down