Skip to content

Commit d56c368

Browse files
committed
graph: ensure that topology subscription cancelation is blocking
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.
1 parent 9c2c95d commit d56c368

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

graph/notifications.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,25 @@ func (b *Builder) SubscribeTopology() (*TopologyClient, error) {
8383
return &TopologyClient{
8484
TopologyChanges: ntfnChan,
8585
Cancel: func() {
86+
// Send the cancellation request.
87+
cancelChan := make(chan *TopologyChange)
8688
select {
8789
case b.ntfnClientUpdates <- &topologyClientUpdate{
8890
cancel: true,
8991
clientID: clientID,
92+
ntfnChan: cancelChan,
9093
}:
9194
case <-b.quit:
9295
return
9396
}
97+
98+
// Block until the cancellation is complete.
99+
select {
100+
case <-cancelChan:
101+
case <-b.quit:
102+
}
103+
104+
return
94105
},
95106
}, nil
96107
}

0 commit comments

Comments
 (0)