Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
fix(actions): survive client disconnects during approved-action dispatch
rcourtmand02a2eb2dc5a
diff --git a/internal/api/actions.go b/internal/api/actions.goindex e9c67f86d3..67aa182699 100644--- a/internal/api/actions.go+++ b/internal/api/actions.go@@ -1,6 +1,7 @@package apiimport (+ "context""encoding/json""errors""io"@@ -512,7 +513,12 @@ func (h *ResourceHandlers) HandleExecuteAction(w http.ResponseWriter, r *http.Rereturn}}- completed, err := h.ActionLifecycle().Execute(r.Context(), orgID, actionID, actor, execution.Reason)+ // Detach dispatch from the client connection: reverse proxies and browsers+ // drop long requests well before slow operations (e.g. docker image pulls)+ // finish, and a cancelled request context would abandon the committed+ // dispatch mid-flight and strand the action in executing. The transport+ // wait stays bounded by the per-operation timeout and server shutdown.+ completed, err := h.ActionLifecycle().Execute(context.WithoutCancel(r.Context()), orgID, actionID, actor, execution.Reason)if err != nil {writeActionLifecycleReadError(w, err, func() {writeActionExecuteError(w, err)diff --git a/internal/api/router.go b/internal/api/router.goindex 877332c48a..97e50b49df 100644--- a/internal/api/router.go+++ b/internal/api/router.go@@ -1345,6 +1345,9 @@ func (r *Router) StartBackgroundWorkers() {r.startLifecycleWorker(func() {r.recoverExecutingActions("system:restart-recovery")})+ r.startLifecycleWorker(func() {+ r.runPeriodicExecutingActionRecovery(r.lifecycleCtx)+ })if r.reportingHandlers != nil {r.startLifecycleWorker(func() {r.reportingHandlers.RunReportScheduleScheduler(r.lifecycleCtx)@@ -1358,6 +1361,36 @@ func (r *Router) StartBackgroundWorkers() {// pass still converges when more actions are stuck than one batch covers.const maxExecutingActionRecoveryBatch = 100+// executingActionRecoveryInterval paces the standing recovery loop. Restart+// and agent-reconnect passes cover their own triggers, but an abandoned+// dispatch (client disconnect, transport timeout, send failure) otherwise+// waits for the owning agent to reconnect — which may never happen while the+// agent stays healthily connected. The periodic pass reconciles those from+// the durable agent receipt within one interval. A pass over zero executing+// actions is one indexed query per org.+const executingActionRecoveryInterval = 2 * time.Minute++// runPeriodicExecutingActionRecovery re-drives the durable-dispatch recovery+// pass on a fixed interval until the router lifecycle context ends.+func (r *Router) runPeriodicExecutingActionRecovery(ctx context.Context) {+ if r == nil || r.resourceHandlers == nil || mock.IsMockEnabled() {+ return+ }+ if ctx == nil {+ ctx = context.Background()+ }+ ticker := time.NewTicker(executingActionRecoveryInterval)+ defer ticker.Stop()+ for {+ select {+ case <-ctx.Done():+ return+ case <-ticker.C:+ r.recoverExecutingActions("system:periodic-recovery")+ }+ }+}+// recoverExecutingActions reconciles actions left in the executing state by a// server restart or a lost agent callback. Every org routes through// Service.RecoverExecutingActions: receipt-pending attempts reconcile