From ec0c7c59894913863ae821c615473a4d6b0f9c35 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 7 Jan 2017 21:18:05 -0800 Subject: [PATCH] routing: fix panic in inner loop of path finding This commit seems to fix a sporadic error within the integration tests which would at times cause a panic when a payment as initiated. This issue was with the way were deleting from the middle of the slice of unvisited nodes within the graph. Assigning the last element to the middle would at times cause a panic the last element may be nil. To fix this, we now manually copy every item over by one, preserving the order of the slice, and possibly fixing the panic once and for all. --- routing/pathfind.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routing/pathfind.go b/routing/pathfind.go index 2c65f9f1..695477ef 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -285,7 +285,7 @@ func findRoute(graph *channeldb.ChannelGraph, target *btcec.PublicKey, // Since we're going to visit this node, we can // remove it from the set of unvisited nodes. - unvisited[i] = unvisited[len(unvisited)-1] + copy(unvisited[i:], unvisited[i+1:]) unvisited[len(unvisited)-1] = nil // Avoid GC leak. unvisited = unvisited[:len(unvisited)-1]