ipn/ipnlocal: debounce extra enqueues in ExtensionHost.AuthReconfigAsync
Fixes tailscale/corp#39065 Signed-off-by: Michael Ben-Ami <mzb@tailscale.com>
This commit is contained in:
committed by
mzbenami
parent
c026be18cc
commit
a57c6457c9
@@ -90,6 +90,11 @@ type ExtensionHost struct {
|
|||||||
|
|
||||||
extByType sync.Map // reflect.Type -> ipnext.Extension
|
extByType sync.Map // reflect.Type -> ipnext.Extension
|
||||||
|
|
||||||
|
// hasPendingAuthReconfig tracks whether an AuthReconfig call
|
||||||
|
// has been enqueued but not yet executed. It avoids redundant
|
||||||
|
// reconfigs and prevents them from piling up in the workQueue.
|
||||||
|
hasPendingAuthReconfig atomic.Bool
|
||||||
|
|
||||||
// mu protects the following fields.
|
// mu protects the following fields.
|
||||||
// It must not be held when calling [LocalBackend] methods
|
// It must not be held when calling [LocalBackend] methods
|
||||||
// or when invoking callbacks registered by extensions.
|
// or when invoking callbacks registered by extensions.
|
||||||
@@ -544,11 +549,17 @@ func (h *ExtensionHost) Shutdown() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AuthReconfigAsync implements [ipnext.Host.AuthReconfigAsync].
|
// AuthReconfigAsync implements [ipnext.Host.AuthReconfigAsync].
|
||||||
|
// Since execution uses the most recent state at execution time,
|
||||||
|
// multiple enqueued calls are redundant and are not enqueued.
|
||||||
func (h *ExtensionHost) AuthReconfigAsync() {
|
func (h *ExtensionHost) AuthReconfigAsync() {
|
||||||
if h == nil {
|
if h == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if h.hasPendingAuthReconfig.Swap(true) {
|
||||||
|
return
|
||||||
|
}
|
||||||
h.enqueueBackendOperation(func(b Backend) {
|
h.enqueueBackendOperation(func(b Backend) {
|
||||||
|
h.hasPendingAuthReconfig.Store(false)
|
||||||
b.authReconfig()
|
b.authReconfig()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user