Merge pull request #2871 from halseth/router-subscribetopology-check-started

routing/notifications: check router started on SubscribeTopology
This commit is contained in:
Olaoluwa Osuntokun 2019-04-16 21:32:10 -07:00 committed by GitHub
commit a3c980b1e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)