From c2af637d3c594bf2827e7a76867ca24dd03582e1 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 2 Apr 2019 10:21:08 +0200 Subject: [PATCH] routing/notifications: check router startd on SubscribeTopology If the router is not yet started, return an error to avoid a deadlock waiting for it to handle the subscription request. --- routing/notifications.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/routing/notifications.go b/routing/notifications.go index dee5300c..f8923308 100644 --- a/routing/notifications.go +++ b/routing/notifications.go @@ -56,6 +56,12 @@ type topologyClientUpdate struct { // nodes appearing, node updating their attributes, new channels, channels // closing, and updates in the routing policies of a channel's directed edges. func (r *ChannelRouter) SubscribeTopology() (*TopologyClient, error) { + // If the router is not yet started, return an error to avoid a + // deadlock waiting for it to handle the subscription request. + if atomic.LoadUint32(&r.started) == 0 { + return nil, fmt.Errorf("router not started") + } + // We'll first atomically obtain the next ID for this client from the // incrementing client ID counter. clientID := atomic.AddUint64(&r.ntfnClientCounter, 1)