From ae6bde2d7768db9526e6eba9c6f26da92aa90aec Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 16 Oct 2017 18:48:21 -0700 Subject: [PATCH] routing: avoid internal bolt db deadlock by reusing transaction in findPath This commit fixes a bug that could lead to a deadlock inside bolt db itself. In a recent commit we allowed a db transaction to be passed directly into findPath, however, the initial call to graph.ForEachNode instead passed a _nil_ transaction causing the method itself to create a _new_ transaction, leading to a deadlock. We fix this issue by instead re-using the transaction pointer. --- routing/pathfind.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/routing/pathfind.go b/routing/pathfind.go index ad55e163..b7afa729 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -392,7 +392,7 @@ func findPath(tx *bolt.Tx, graph *channeldb.ChannelGraph, // map for the node set with a distance of "infinity". We also mark // add the node to our set of unvisited nodes. distance := make(map[vertex]nodeWithDist) - if err := graph.ForEachNode(nil, func(_ *bolt.Tx, node *channeldb.LightningNode) error { + if err := graph.ForEachNode(tx, func(_ *bolt.Tx, node *channeldb.LightningNode) error { // TODO(roasbeef): with larger graph can just use disk seeks // with a visited map distance[newVertex(node.PubKey)] = nodeWithDist{ @@ -423,7 +423,6 @@ func findPath(tx *bolt.Tx, graph *channeldb.ChannelGraph, // We'll use this map as a series of "previous" hop pointers. So to get // to `vertex` we'll take the edge that it's mapped to within `prev`. prev := make(map[vertex]edgeWithPrev) - for nodeHeap.Len() != 0 { // Fetch the node within the smallest distance from our source // from the heap.