ipn/ipnlocal: add mutex to webClient struct

Adds a new sync.Mutex field to the webClient struct, rather than
using the general LocalBackend mutex. Since webClientGetOrInit
(previously WebClientInit) gets called on every connection, we
want to avoid holding the lock on LocalBackend just to check if
the server is initialized.

Moves all web_client.go funcs over to using the webClient.mu field.

Updates tailscale/corp#14335

Signed-off-by: Sonia Appasamy <sonia@tailscale.com>
This commit is contained in:
Sonia Appasamy
2023-11-15 17:40:37 -05:00
committed by Sonia Appasamy
parent 7d4221c295
commit 055394f3be
3 changed files with 34 additions and 27 deletions

View File

@@ -656,7 +656,7 @@ func (b *LocalBackend) Shutdown() {
b.debugSink = nil
}
b.mu.Unlock()
b.WebClientShutdown()
b.webClientShutdown()
if b.sockstatLogger != nil {
b.sockstatLogger.Shutdown()
@@ -4252,7 +4252,7 @@ func (b *LocalBackend) setWebClientAtomicBoolLocked(nm *netmap.NetworkMap, prefs
shouldRun := prefs.Valid() && prefs.RunWebClient()
wasRunning := b.webClientAtomicBool.Swap(shouldRun)
if wasRunning && !shouldRun {
go b.WebClientShutdown() // stop web client
go b.webClientShutdown() // stop web client
}
}