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.
This commit is contained in:
parent
0692d2d408
commit
ae6bde2d77
@ -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
|
// map for the node set with a distance of "infinity". We also mark
|
||||||
// add the node to our set of unvisited nodes.
|
// add the node to our set of unvisited nodes.
|
||||||
distance := make(map[vertex]nodeWithDist)
|
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
|
// TODO(roasbeef): with larger graph can just use disk seeks
|
||||||
// with a visited map
|
// with a visited map
|
||||||
distance[newVertex(node.PubKey)] = nodeWithDist{
|
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
|
// 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`.
|
// to `vertex` we'll take the edge that it's mapped to within `prev`.
|
||||||
prev := make(map[vertex]edgeWithPrev)
|
prev := make(map[vertex]edgeWithPrev)
|
||||||
|
|
||||||
for nodeHeap.Len() != 0 {
|
for nodeHeap.Len() != 0 {
|
||||||
// Fetch the node within the smallest distance from our source
|
// Fetch the node within the smallest distance from our source
|
||||||
// from the heap.
|
// from the heap.
|
||||||
|
Loading…
Reference in New Issue
Block a user