fix: cache daemon ID at init to prevent Podman token binding conflicts

Podman can return unstable or empty daemon IDs across API calls. When
the agent fetched info.ID on every report cycle, this could cause the
agent identity to change mid-session, triggering "token already in use"
errors on the server.

Cache the daemon ID at initialization and use it consistently for all
reports.

Related to #740
This commit is contained in:
rcourtman 2025-11-26 10:23:22 +00:00
parent d07ad8fd3e
commit 7f449d30e0

View file

@ -87,6 +87,7 @@ type Agent struct {
cfg Config
docker *client.Client
daemonHost string
daemonID string // Cached at init; Podman can return unstable IDs across calls
runtime RuntimeKind
runtimeVer string
agentVersion string
@ -238,6 +239,7 @@ func New(cfg Config) (*Agent, error) {
cfg: cfg,
docker: dockerClient,
daemonHost: dockerClient.DaemonHost(),
daemonID: info.ID, // Cache at init for stable agent ID
runtime: runtimeKind,
runtimeVer: info.ServerVersion,
agentVersion: agentVersion,
@ -622,7 +624,10 @@ func (a *Agent) buildReport(ctx context.Context) (agentsdocker.Report, error) {
agentID := a.cfg.AgentID
if agentID == "" {
agentID = info.ID
// Use cached daemon ID from init rather than info.ID from current call.
// Podman can return different/empty IDs across calls, causing token
// binding conflicts on the server.
agentID = a.daemonID
}
if agentID == "" {
agentID = a.machineID