From bfdb2bebe27ffef8f1b1167cdb134d3077529de4 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 17 Apr 2017 16:06:43 -0700 Subject: [PATCH] test: bind the inner lightningNetworkWatcher goroutine to the wait group MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes a race condition detected by the race condition detector that can be triggered by the lightnignNode exiting while the underlying node is still active. Since the wait group wasn’t tied to this cog routine, when the main process was exiting, it wouldn’t also wait for this grouting to exit, thus triggering a race condition of modifying the channel reference while reading for it. The fix for this is straightforward: we now ensure that the goroutine is factored into the struct level wait group. --- networktest.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/networktest.go b/networktest.go index 780d7d92..d074ce4f 100644 --- a/networktest.go +++ b/networktest.go @@ -351,7 +351,10 @@ func (l *lightningNode) lightningNetworkWatcher() { } graphUpdates := make(chan *lnrpc.GraphTopologyUpdate) + l.wg.Add(1) go func() { + defer l.wg.Done() + ctxb := context.Background() req := &lnrpc.GraphTopologySubscription{} topologyClient, err := l.SubscribeChannelGraph(ctxb, req) @@ -748,7 +751,7 @@ out: } // Now that the initial test network has been initialized, launch the - // network wather. + // network watcher. go n.networkWatcher() return nil