From c2c23f66fed26d9a6a3c95488c19f7cdbb47f8fd Mon Sep 17 00:00:00 2001 From: riccardom Date: Wed, 10 Jun 2026 14:30:02 +0200 Subject: [PATCH] Fixes DisableAutoConnect semantics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DisableAutoConnect semantics ============================ Scope: governs ONLY the service-Start auto-connect decision. Once the connection goroutine has been spawned (by any path), the flag is never consulted again — the retry loop keeps trying to connect until ctx is cancelled by Down / Stop / Logout. Cases ----- 1. Service Start + DisableAutoConnect = true - No connection goroutine spawned. - clientRunning stays false. - State set to StatusIdle. - Daemon stays passive until an explicit Up RPC. 2. Service Start + DisableAutoConnect = false - Spawn connectWithRetryRuns. - clientRunning = true. - Retry loop runs until ctx cancelled. 3. Up RPC (any value of DisableAutoConnect) - Flag ignored. The user / admin explicitly asked to connect — by definition not "auto". - Spawn connectWithRetryRuns. - clientRunning = true. 4. MDM-triggered restart (any value of DisableAutoConnect) - Flag ignored. An MDM policy change applies new config to an already-running engine; treated as an implicit Up. - Spawn connectWithRetryRuns. - clientRunning = true. 5. Down / Stop / Logout - Cancels ctx → connectWithRetryRuns exits → close(giveUpChan). - cleanupConnection clears clientRunning = false. - DisableAutoConnect not involved. Prepare for next step Collapse error log into s.connect and rename it to more explicit connectOnce --- client/server/server.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/client/server/server.go b/client/server/server.go index 397fb37e4..3a3193da7 100644 --- a/client/server/server.go +++ b/client/server/server.go @@ -218,7 +218,7 @@ func (s *Server) Start() error { // connectWithRetryRuns runs the client connection with a backoff strategy where we retry the operation as additional // mechanism to keep the client connected even when the connection is lost. -// we cancel retry if the client receive a stop or down command, or if disable auto connect is configured. +// we cancel retry if the client receive a stop or down command. func (s *Server) connectWithRetryRuns(ctx context.Context, profileConfig *profilemanager.Config, statusRecorder *peer.Status, runningChan chan struct{}, giveUpChan chan struct{}) { defer func() { s.mutex.Lock() @@ -226,14 +226,6 @@ func (s *Server) connectWithRetryRuns(ctx context.Context, profileConfig *profil s.mutex.Unlock() }() - if s.config.DisableAutoConnect { - if err := s.connect(ctx, s.config, s.statusRecorder, runningChan); err != nil { - log.Debugf("run client connection exited with error: %v", err) - } - log.Tracef("client connection exited") - return - } - backOff := getConnectWithBackoff(ctx) go func() { t := time.NewTicker(24 * time.Hour) @@ -1663,6 +1655,7 @@ func (s *Server) connect(ctx context.Context, config *profilemanager.Config, sta s.mutex.Unlock() if err := client.Run(runningChan, s.logFile); err != nil { + log.Debugf("run client connection exited with error: %v", err) return err } return nil