cmd/tailscale: avoid deadlocking between backend calls and callbacks

The runBackend goroutine issues backend requests (StartLoginInteractive,
Logout, SetPrefs) from the same select that receives callbacks the
backend.

Avoid the potential for same-goroutine deadlock by issuing backend requests on
separate goroutines.

Fixes tailscale/tailscale#470

Signed-off-by: Elias Naur <mail@eliasnaur.com>
pull/2/head
Elias Naur 5 years ago
parent dd2cdacbed
commit 0d0a049057

@ -224,15 +224,15 @@ func (a *App) runBackend() error {
case e := <-a.backend: case e := <-a.backend:
switch e := e.(type) { switch e := e.(type) {
case ReauthEvent: case ReauthEvent:
b.backend.StartLoginInteractive() go b.backend.StartLoginInteractive()
case LogoutEvent: case LogoutEvent:
b.backend.Logout() go b.backend.Logout()
case ConnectEvent: case ConnectEvent:
prefs.mu.Lock() prefs.mu.Lock()
p := prefs.prefs p := prefs.prefs
prefs.mu.Unlock() prefs.mu.Unlock()
p.WantRunning = e.Enable p.WantRunning = e.Enable
b.backend.SetPrefs(p) go b.backend.SetPrefs(p)
} }
case s := <-onConnect: case s := <-onConnect:
jni.Do(a.jvm, func(env jni.Env) error { jni.Do(a.jvm, func(env jni.Env) error {

Loading…
Cancel
Save