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.
This commit is contained in:
parent
0db384fd6b
commit
57a7d58ef9
@ -12,6 +12,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -339,6 +340,12 @@ type chanWatchRequest struct {
|
|||||||
func (l *lightningNode) lightningNetworkWatcher() {
|
func (l *lightningNode) lightningNetworkWatcher() {
|
||||||
defer l.wg.Done()
|
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)
|
graphUpdates := make(chan *lnrpc.GraphTopologyUpdate)
|
||||||
go func() {
|
go func() {
|
||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
@ -357,6 +364,20 @@ func (l *lightningNode) lightningNetworkWatcher() {
|
|||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
return
|
return
|
||||||
} else if err != nil {
|
} 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
|
// Similar to the case above, we also panic
|
||||||
// here (and end the tests) as these
|
// here (and end the tests) as these
|
||||||
// notifications are critical to the success of
|
// notifications are critical to the success of
|
||||||
|
Loading…
Reference in New Issue
Block a user