cmd/tailscaled: graceful shutdown (#534)

Signed-off-by: Dmytro Shynkevych <dmytro@tailscale.com>
This commit is contained in:
Dmytro Shynkevych
2020-07-13 06:17:58 -04:00
committed by GitHub
parent 6255ce55df
commit 61abab999e
5 changed files with 40 additions and 7 deletions

View File

@@ -224,6 +224,7 @@ func Run(rctx context.Context, logf logger.Logf, logid string, opts Options, e w
}
stopAll()
b.Shutdown()
return rctx.Err()
}

View File

@@ -49,6 +49,7 @@ type LocalBackend struct {
store StateStore
backendLogID string
portpoll *portlist.Poller // may be nil
portpollOnce sync.Once
newDecompressor func() (controlclient.Decompressor, error)
// TODO: these fields are accessed unsafely by concurrent
@@ -387,8 +388,10 @@ func (b *LocalBackend) Start(opts Options) error {
// At this point, we have finished using hostinfo without synchronization,
// so it is safe to start readPoller which concurrently writes to it.
if b.portpoll != nil {
go b.portpoll.Run(b.ctx)
go b.readPoller()
b.portpollOnce.Do(func() {
go b.portpoll.Run(b.ctx)
go b.readPoller()
})
}
b.mu.Lock()