From f4c426cbdf07d690ce007c4e915fd3de247fa268 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Thu, 25 Dec 2025 08:09:42 +0000 Subject: [PATCH] fix: Properly close command client WebSocket when disabling remotely When the server disables command execution for an agent, we now properly call Close() on the command client to tear down the WebSocket connection. Previously we just set the pointer to nil which left the goroutine running with an orphaned connection. --- internal/hostagent/agent.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/hostagent/agent.go b/internal/hostagent/agent.go index 8f63e9561..603ed165f 100644 --- a/internal/hostagent/agent.go +++ b/internal/hostagent/agent.go @@ -462,7 +462,10 @@ func (a *Agent) applyRemoteConfig(commandsEnabled bool) { } else if !commandsEnabled && currentlyEnabled { // Server disabled commands, but we have a command client running a.logger.Info().Msg("Server disabled command execution - stopping command client") - // Signal stop (the command client will exit on next iteration) + // Properly close the WebSocket connection to stop the client + if err := a.commandClient.Close(); err != nil { + a.logger.Debug().Err(err).Msg("Error closing command client connection") + } a.commandClient = nil } }