test: bind the inner lightningNetworkWatcher goroutine to the wait group

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.
This commit is contained in:
Olaoluwa Osuntokun 2017-04-17 16:06:43 -07:00
parent 4939443512
commit bfdb2bebe2
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
1 changed files with 4 additions and 1 deletions

View File

@ -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