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.
This commit is contained in:
rcourtman
2025-12-25 08:09:42 +00:00
parent a38c071644
commit f4c426cbdf
+4 -1
View File
@@ -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
}
}