From b4b3fae4c40f87fd1ba1d1204aa78d32d1f4b508 Mon Sep 17 00:00:00 2001 From: TerrifiedBug Date: Thu, 5 Mar 2026 19:26:26 +0000 Subject: [PATCH] fix: prevent self-update re-exec loop and orphaned Vector processes - Skip update when already running target version (breaks re-exec loop) - Shut down all pipelines before syscall.Exec to prevent port conflicts --- agent/internal/agent/agent.go | 4 ++++ agent/internal/agent/updater.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/agent/internal/agent/agent.go b/agent/internal/agent/agent.go index 1631323..ac98d72 100644 --- a/agent/internal/agent/agent.go +++ b/agent/internal/agent/agent.go @@ -151,6 +151,10 @@ func (a *Agent) handlePendingAction(action *client.PendingAction) { a.updateError = "running in Docker" return } + if action.TargetVersion == Version { + slog.Debug("already running target version, skipping update", "version", Version) + return + } if action.TargetVersion == a.failedUpdateVersion { return // already failed for this version, don't retry } diff --git a/agent/internal/agent/updater.go b/agent/internal/agent/updater.go index 8c0d123..45530fd 100644 --- a/agent/internal/agent/updater.go +++ b/agent/internal/agent/updater.go @@ -84,6 +84,11 @@ func (a *Agent) handleSelfUpdate(action *client.PendingAction) error { return fmt.Errorf("replace executable: %w", err) } + // Shut down all pipelines before re-exec to avoid orphaned Vector processes + // and port conflicts when the new agent starts them again. + slog.Info("stopping all pipelines before re-exec") + a.supervisor.ShutdownAll() + slog.Info("binary replaced, re-executing", "path", execPath, "version", action.TargetVersion) // Re-exec the process — this replaces the current process entirely