Skip to content

Commit 6e2f2bb

Browse files
creachadairtomhjp
authored andcommitted
ipn/ipnlocal: do not stall event processing for appc route updates (tailscale#17663)
A follow-up to tailscale#17411. Put AppConnector events into a task queue, as they may take some time to process. Ensure that the queue is stopped at shutdown so that cleanup will remain orderly. Because events are delivered on a separate goroutine, slow processing of an event does not cause an immediate problem; however, a subscriber that blocks for a long time will push back on the bus as a whole. See https://godoc.org/tailscale.com/util/eventbus#hdr-Expected_subscriber_behavior for more discussion. Updates tailscale#17192 Updates tailscale#15160 Change-Id: Ib313cc68aec273daf2b1ad79538266c81ef063e3 Signed-off-by: M. J. Fromberger <fromberger@tailscale.com> (cherry picked from commit 06b0923)
1 parent faca4c0 commit 6e2f2bb

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

ipn/ipnlocal/local.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import (
8787
"tailscale.com/util/clientmetric"
8888
"tailscale.com/util/dnsname"
8989
"tailscale.com/util/eventbus"
90+
"tailscale.com/util/execqueue"
9091
"tailscale.com/util/goroutines"
9192
"tailscale.com/util/mak"
9293
"tailscale.com/util/osuser"
@@ -187,6 +188,7 @@ type LocalBackend struct {
187188
statsLogf logger.Logf // for printing peers stats on change
188189
sys *tsd.System
189190
eventSubs eventbus.Monitor
191+
appcTask execqueue.ExecQueue // handles updates from appc
190192

191193
health *health.Tracker // always non-nil
192194
polc policyclient.Client // always non-nil
@@ -642,12 +644,14 @@ func (b *LocalBackend) consumeEventbusTopics(ec *eventbus.Client) func(*eventbus
642644
// We need to find a way to ensure that changes to the backend state are applied
643645
// consistently in the presnce of profile changes, which currently may not happen in
644646
// a single atomic step. See: https://github.com/tailscale/tailscale/issues/17414
645-
if err := b.AdvertiseRoute(ru.Advertise...); err != nil {
646-
b.logf("appc: failed to advertise routes: %v: %v", ru.Advertise, err)
647-
}
648-
if err := b.UnadvertiseRoute(ru.Unadvertise...); err != nil {
649-
b.logf("appc: failed to unadvertise routes: %v: %v", ru.Unadvertise, err)
650-
}
647+
b.appcTask.Add(func() {
648+
if err := b.AdvertiseRoute(ru.Advertise...); err != nil {
649+
b.logf("appc: failed to advertise routes: %v: %v", ru.Advertise, err)
650+
}
651+
if err := b.UnadvertiseRoute(ru.Unadvertise...); err != nil {
652+
b.logf("appc: failed to unadvertise routes: %v: %v", ru.Unadvertise, err)
653+
}
654+
})
651655
case ri := <-storeRoutesSub.Events():
652656
// Whether or not routes should be stored can change over time.
653657
shouldStoreRoutes := b.ControlKnobs().AppCStoreRoutes.Load()
@@ -1113,6 +1117,7 @@ func (b *LocalBackend) Shutdown() {
11131117
// they can deadlock with c.Shutdown().
11141118
// 2. LocalBackend.consumeEventbusTopics event handlers may not guard against
11151119
// undesirable post/in-progress LocalBackend.Shutdown() behaviors.
1120+
b.appcTask.Shutdown()
11161121
b.eventSubs.Close()
11171122

11181123
b.em.close()

0 commit comments

Comments
 (0)