Skip to content

Commit

Permalink
graph: ensure that topology subscription cancelation is blocking
Browse files Browse the repository at this point in the history
We want to ensure that when a caller cancels a topology subscription,
then any channel/node updates after that are not notified on the
subscription. To ensure this, we make the Cancel function blocking.
  • Loading branch information
ellemouton committed Feb 13, 2025
1 parent 9c2c95d commit d56c368
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions graph/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,25 @@ func (b *Builder) SubscribeTopology() (*TopologyClient, error) {
return &TopologyClient{
TopologyChanges: ntfnChan,
Cancel: func() {
// Send the cancellation request.
cancelChan := make(chan *TopologyChange)
select {
case b.ntfnClientUpdates <- &topologyClientUpdate{
cancel: true,
clientID: clientID,
ntfnChan: cancelChan,
}:
case <-b.quit:
return
}

// Block until the cancellation is complete.
select {
case <-cancelChan:
case <-b.quit:
}

return

Check failure on line 104 in graph/notifications.go

View workflow job for this annotation

GitHub Actions / lint code

S1023: redundant `return` statement (gosimple)
},
}, nil
}
Expand Down

0 comments on commit d56c368

Please sign in to comment.