From 6db4ee7a3b7bd21775a9f28d7eed640b8f60e4a8 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Thu, 27 Nov 2025 16:22:16 +0000 Subject: [PATCH] fix: clear stale errors after successful cluster operations Previously, errors stored in ClusterClient.lastError were only cleared during initial health checks or when recovering unhealthy nodes. This caused stale error messages to persist in the UI even after the underlying issues were resolved. The fix clears cached errors in two places: 1. After passing connectivity test in getHealthyClient() 2. After successful operation in executeWithFailover() This ensures that once an endpoint starts working again, any previous error messages are cleared from the UI without requiring a restart. Related to #659, #754 --- pkg/proxmox/cluster_client.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/proxmox/cluster_client.go b/pkg/proxmox/cluster_client.go index 61350f5..8fb8cd3 100644 --- a/pkg/proxmox/cluster_client.go +++ b/pkg/proxmox/cluster_client.go @@ -363,6 +363,9 @@ func (cc *ClusterClient) getHealthyClient(ctx context.Context) (*Client, error) Int("nodes", len(testNodes)). Msg("Cluster endpoint passed connectivity test") + // Clear any stale error from previous failures now that connectivity succeeded + delete(cc.lastError, selectedEndpoint) + // Create the actual client with full timeout newClient, err := NewClient(cfg) if err != nil { @@ -397,6 +400,13 @@ func (cc *ClusterClient) markUnhealthyWithError(endpoint string, errMsg string) cc.lastHealthCheck[endpoint] = time.Now() } +// clearEndpointError removes any cached error for an endpoint after successful operations +func (cc *ClusterClient) clearEndpointError(endpoint string) { + cc.mu.Lock() + defer cc.mu.Unlock() + delete(cc.lastError, endpoint) +} + // recoverUnhealthyNodes attempts to recover unhealthy nodes func (cc *ClusterClient) recoverUnhealthyNodes(ctx context.Context) { cc.mu.RLock() @@ -570,6 +580,8 @@ func (cc *ClusterClient) executeWithFailover(ctx context.Context, fn func(*Clien // Execute the function err = fn(client) if err == nil { + // Clear any stale error for this endpoint on success + cc.clearEndpointError(clientEndpoint) return nil } lastErr = err