Skip to content

Commit

Permalink
pool: Don't potentially leak paymgr goroutine.
Browse files Browse the repository at this point in the history
This ensures the goroutine in the payment manager that handles sending
rescan responses respects the context so it does not potentially leak
the goroutine if the context is canceled prior to receiving a response.

It also corrects the channel close logic by moving into the goroutine.
As mentioned in previous commits, receivers should never close channels,
only senders once they are sure there are no more goroutines that can
write to the channel.
  • Loading branch information
davecgh authored and jholdstock committed Sep 26, 2023
1 parent 445e130 commit df05352
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pool/paymentmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,18 +556,21 @@ func fetchRescanResponse(ctx context.Context, rescanSource func() (*walletrpc.Re
respCh := make(chan *rescanMsg)
go func(ch chan *rescanMsg) {
resp, err := rescanSource()
ch <- &rescanMsg{
select {
case <-ctx.Done():
case ch <- &rescanMsg{
resp: resp,
err: err,
}:
}
close(ch)
}(respCh)

select {
case <-ctx.Done():
log.Tracef("%s: context cancelled fetching rescan response", funcName)
return nil, errs.ContextCancelled
case msg := <-respCh:
close(respCh)
if msg.err != nil {
desc := fmt.Sprintf("%s: unable fetch wallet rescan response, %s",
funcName, msg.err)
Expand Down

0 comments on commit df05352

Please sign in to comment.