From e19614ff3f1e51e890cee92a92abeb32872abb86 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 8 Jan 2018 17:44:28 -0800 Subject: [PATCH] pilot: fix goroutine leak by also draining UnconfirmedTransactions notifications --- pilot.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pilot.go b/pilot.go index ce27142b..b407fe51 100644 --- a/pilot.go +++ b/pilot.go @@ -197,6 +197,24 @@ func initAutoPilot(svr *server, cfg *autoPilotConfig) (*autopilot.Agent, error) } } + }() + go func() { + defer txnSubscription.Cancel() + defer svr.wg.Done() + + for { + select { + // We won't act upon new unconfirmed transaction, as + // we'll only use confirmed outputs when funding. + // However, we will still drain this request in order + // to avoid goroutine leaks, and ensure we promptly + // read from the channel if available. + case <-txnSubscription.UnconfirmedTransactions(): + case <-svr.quit: + return + } + } + }() // We'll also launch a goroutine to provide the agent with