From 57a7d58ef92fe7e614c4f96c3a555a8934ab59fc Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 16 Mar 2017 12:15:37 -0700 Subject: [PATCH] test: don't panic within lightningNetworkWatcher if lnd is shutting down This commit fixes an issue in the newly added integration tests level topology notifications that caused tests to erronosely panic when the daemon was detected to be shutting down. This issue was notified by AndrewSamokhvalov. We fix this issue by checking if the error is a shutdown error, and exiting early if so. Additionally we add a fail-fast case if the quit channel for the node has already been closed. --- networktest.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/networktest.go b/networktest.go index 04e21b1bf..c0b35c780 100644 --- a/networktest.go +++ b/networktest.go @@ -12,6 +12,7 @@ import ( "path/filepath" "runtime" "strconv" + "strings" "sync" "time" @@ -339,6 +340,12 @@ type chanWatchRequest struct { func (l *lightningNode) lightningNetworkWatcher() { defer l.wg.Done() + // If the channel router is shutting down, then we won't consider it as + // a real error. This just indicates the daemon itself is quitting. + isShutdownError := func(err error) bool { + return strings.Contains(err.Error(), "shutting down") + } + graphUpdates := make(chan *lnrpc.GraphTopologyUpdate) go func() { ctxb := context.Background() @@ -357,6 +364,20 @@ func (l *lightningNode) lightningNetworkWatcher() { if err == io.EOF { return } else if err != nil { + // If the node has been signalled to quit, then + // we'll exit early. + select { + case <-l.quit: + return + default: + } + + // Otherwise, if the node is shutting down on + // it's own, then we'll also bail out early. + if isShutdownError(err) { + return + } + // Similar to the case above, we also panic // here (and end the tests) as these // notifications are critical to the success of