mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-16 03:31:39 +00:00
ipn/ipnlocal: add LocalBackend.broadcastStatusChanged
To reduce repetition. Also, document why we acquire the lock. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
parent
b7ede14396
commit
45d3174c0d
@ -601,18 +601,12 @@ func (b *LocalBackend) findExitNodeIDLocked(nm *netmap.NetworkMap) (prefsChanged
|
|||||||
func (b *LocalBackend) setWgengineStatus(s *wgengine.Status, err error) {
|
func (b *LocalBackend) setWgengineStatus(s *wgengine.Status, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.logf("wgengine status error: %v", err)
|
b.logf("wgengine status error: %v", err)
|
||||||
|
b.broadcastStatusChanged()
|
||||||
b.statusLock.Lock()
|
|
||||||
b.statusChanged.Broadcast()
|
|
||||||
b.statusLock.Unlock()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if s == nil {
|
if s == nil {
|
||||||
b.logf("[unexpected] non-error wgengine update with status=nil: %v", s)
|
b.logf("[unexpected] non-error wgengine update with status=nil: %v", s)
|
||||||
|
b.broadcastStatusChanged()
|
||||||
b.statusLock.Lock()
|
|
||||||
b.statusChanged.Broadcast()
|
|
||||||
b.statusLock.Unlock()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -632,12 +626,18 @@ func (b *LocalBackend) setWgengineStatus(s *wgengine.Status, err error) {
|
|||||||
}
|
}
|
||||||
b.stateMachine()
|
b.stateMachine()
|
||||||
}
|
}
|
||||||
|
b.broadcastStatusChanged()
|
||||||
|
b.send(ipn.Notify{Engine: &es})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *LocalBackend) broadcastStatusChanged() {
|
||||||
|
// The sync.Cond docs say: "It is allowed but not required for the caller to hold c.L during the call."
|
||||||
|
// In this particular case, we must acquire b.statusLock. Otherwise we might broadcast before
|
||||||
|
// the waiter (in requestEngineStatusAndWait) starts to wait, in which case
|
||||||
|
// the waiter can get stuck indefinitely. See PR 2865.
|
||||||
b.statusLock.Lock()
|
b.statusLock.Lock()
|
||||||
b.statusChanged.Broadcast()
|
b.statusChanged.Broadcast()
|
||||||
b.statusLock.Unlock()
|
b.statusLock.Unlock()
|
||||||
|
|
||||||
b.send(ipn.Notify{Engine: &es})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func endpointsEqual(x, y []tailcfg.Endpoint) bool {
|
func endpointsEqual(x, y []tailcfg.Endpoint) bool {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user