mirror of
https://github.com/tailscale/tailscale.git
synced 2026-03-26 02:03:42 -04:00
tsnet: print state change in auth loop more responsively (#18048)
tsnet has a 5s sleep as part of its logic waiting to log successful auth. Add an additional channel that will interrupt this sleep early if the local backend's state changes before then. This is early enough in the bootstrap logic that the local client has not been set up yet, so we subscribe directly on the local backend in keeping with the rest of the function, but it would be nice to port the whole function to the new eventbus in a separate change. Note this does not affect how quickly auth actually happens, it just ensures we more responsively log the fact that auth state has changed. Updates #16340 Change-Id: I7a28fd3927bbcdead9a5aad39f4a3596b5f659b0 Signed-off-by: Tom Proctor <tomhjp@users.noreply.github.com>
This commit is contained in:
@@ -946,6 +946,22 @@ func (s *Server) logf(format string, a ...any) {
|
||||
// printAuthURLLoop loops once every few seconds while the server is still running and
|
||||
// is in NeedsLogin state, printing out the auth URL.
|
||||
func (s *Server) printAuthURLLoop() {
|
||||
ctx, cancel := context.WithCancel(s.shutdownCtx)
|
||||
defer cancel()
|
||||
stateCh := make(chan struct{}, 1)
|
||||
go s.lb.WatchNotifications(ctx, ipn.NotifyInitialState, nil, func(n *ipn.Notify) (keepGoing bool) {
|
||||
if n.State == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
// No need to block, we only want to make sure the loop below is not
|
||||
// blocking on time.After if there's a new state available.
|
||||
select {
|
||||
case stateCh <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
return true
|
||||
})
|
||||
for {
|
||||
if s.shutdownCtx.Err() != nil {
|
||||
return
|
||||
@@ -960,6 +976,7 @@ func (s *Server) printAuthURLLoop() {
|
||||
}
|
||||
select {
|
||||
case <-time.After(5 * time.Second):
|
||||
case <-stateCh:
|
||||
case <-s.shutdownCtx.Done():
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user