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.
This commit is contained in:
Johan T. Halseth 2019-04-02 10:21:08 +02:00
parent 893cff60c4
commit c2af637d3c
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -56,6 +56,12 @@ type topologyClientUpdate struct {
// nodes appearing, node updating their attributes, new channels, channels // nodes appearing, node updating their attributes, new channels, channels
// closing, and updates in the routing policies of a channel's directed edges. // closing, and updates in the routing policies of a channel's directed edges.
func (r *ChannelRouter) SubscribeTopology() (*TopologyClient, error) { 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 // We'll first atomically obtain the next ID for this client from the
// incrementing client ID counter. // incrementing client ID counter.
clientID := atomic.AddUint64(&r.ntfnClientCounter, 1) clientID := atomic.AddUint64(&r.ntfnClientCounter, 1)