feature,ipn/ipnlocal,wgengine: improve how eventbus shutdown is handled (#17156)

Instead of waiting for a designated subscription to close as a canary for the
bus being stopped, use the bus Client's own signal for closure added in #17118.

Updates #cleanup

Change-Id: I384ea39f3f1f6a030a6282356f7b5bdcdf8d7102
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
This commit is contained in:
M. J. Fromberger
2025-09-16 10:52:39 -07:00
committed by GitHub
parent b63f5d7e7d
commit 8608e42103
5 changed files with 9 additions and 22 deletions
+2 -4
View File
@@ -68,15 +68,13 @@ func newExpiryManager(logf logger.Logf, bus *eventbus.Bus) *expiryManager {
// [eventbus.Subscriber]'s and passes them to their related handler. Events are
// always handled in the order they are received, i.e. the next event is not
// read until the previous event's handler has returned. It returns when the
// [controlclient.ControlTime] subscriber is closed, which is interpreted to be the
// same as the [eventbus.Client] closing ([eventbus.Subscribers] are either
// all open or all closed).
// [eventbus.Client] is closed.
func (em *expiryManager) consumeEventbusTopics() {
defer close(em.subsDoneCh)
for {
select {
case <-em.controlTimeSub.Done():
case <-em.eventClient.Done():
return
case time := <-em.controlTimeSub.Events():
em.onControlTime(time.Value)
+2 -7
View File
@@ -619,18 +619,13 @@ func NewLocalBackend(logf logger.Logf, logID logid.PublicID, sys *tsd.System, lo
// [eventbus.Subscriber]'s and passes them to their related handler. Events are
// always handled in the order they are received, i.e. the next event is not
// read until the previous event's handler has returned. It returns when the
// [tailcfg.ClientVersion] subscriber is closed, which is interpreted to be the
// same as the [eventbus.Client] closing ([eventbus.Subscribers] are either
// all open or all closed).
// [eventbus.Client] is closed.
func (b *LocalBackend) consumeEventbusTopics() {
defer close(b.subsDoneCh)
for {
select {
// TODO(cmol): Move to using b.eventClient.Done() once implemented.
// In the meantime, we rely on the subs not going away until the client is
// closed, closing all its subscribers.
case <-b.clientVersionSub.Done():
case <-b.eventClient.Done():
return
case clientVersion := <-b.clientVersionSub.Events():
b.onClientVersion(&clientVersion)