Skip to content

Commit

Permalink
Attempt to fix leak using callback from stdbus
Browse files Browse the repository at this point in the history
  • Loading branch information
mtryfoss committed Jul 2, 2020
1 parent b59fa27 commit 21fe6fb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion client/bus/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,24 @@ func (b *subBus) Close() {
// TODO: Ultimately, we will need to derive a way to check to see if the parent bus is then unused, in which case, the NATS subscription(s) should then be closed.
}

func (b *subBus) Cancel(s ari.Subscription) {
for i, si := range b.subs {
if s == si {
b.subs[i] = b.subs[len(b.subs)-1] // replace the current with the end
b.subs[len(b.subs)-1] = nil // remove the end
b.subs = b.subs[:len(b.subs)-1] // lop off the end
break
}
}
}

func (b *subBus) Send(e ari.Event) {
b.bus.Send(e)
}

func (b *subBus) Subscribe(key *ari.Key, eTypes ...string) ari.Subscription {
sub := b.bus.Subscribe(key, eTypes...)

sub.SetCallback(b.Cancel)
b.subs = append(b.subs, sub)

return sub
Expand Down

0 comments on commit 21fe6fb

Please sign in to comment.