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(notifications): honour service-unavailable retry hints
pulse-triage[bot]7a92b60cd99b
diff --git a/docs/release-control/v6/internal/subsystems/notifications.md b/docs/release-control/v6/internal/subsystems/notifications.mdindex 22ebb76e1f..7392a09640 100644--- a/docs/release-control/v6/internal/subsystems/notifications.md+++ b/docs/release-control/v6/internal/subsystems/notifications.md@@ -139,16 +139,24 @@ negative overflow cases alongside ordinary seconds, dates, whitespace andinvalid inputs. This is pure parser proof: it does not establish elapsed HTTPretry timing, queue persistence, provider acceptance or recipient receipt.-For HTTP 429 transport retries, a valid `Retry-After` overrides only the wait+For HTTP 429 and 503 transport retries, a valid `Retry-After` overrides only the waitfollowing that response. It must not replace the independent exponentialbackoff schedule. In particular, a zero-delay response cannot cause laterheaderless 429 or 503 failures to exhaust their remaining retries immediately.The schedule continues doubling up to `WebhookMaxBackoff`; retry budgets,classification, parsing and the existing header-delay cap remain unchanged.-This does not extend header handling to 503 responses.+503 recovery hints use the same bounded parser as 429 rate-limit hints, as+described by RFC 9110 section 10.2.3. Invalid or absent hints retain exponential+backoff; other status codes do not gain header-based delay handling.++`TestSendWebhookWithRetry_ServiceUnavailableRetryAfter` in+`internal/notifications/webhook_enhanced_test.go` verifies that a 503 carrying+`Retry-After: 2` delays the next HTTP request by at least two seconds, rather+than the initial one-second backoff, and that a malformed hint retains that+initial backoff. It uses an owned loopback destination, not a live provider.`TestSendWebhookWithRetry_ZeroRetryAfterPreservesLaterBackoff` in-`internal/notifications/webhook_enhanced_test.go` sends a zero-delay 429,+`internal/notifications/webhook_enhanced_test.go` sends a zero-delay 429 or 503,then a headerless 429 or 503, then success through a local HTTP fixture. Itverifies three requests and the two-second exponential wait before the finalrequest. This is transport timing proof, not durable queue retry, installeddiff --git a/internal/notifications/webhook_enhanced.go b/internal/notifications/webhook_enhanced.goindex 3c8d79a3c0..8580e39b3e 100644--- a/internal/notifications/webhook_enhanced.go+++ b/internal/notifications/webhook_enhanced.go@@ -322,7 +322,9 @@ func (n *NotificationManager) sendWebhookWithRetry(webhook EnhancedWebhookConfigfor attempt := 0; attempt <= maxRetries; attempt++ {if attempt > 0 {// Check for Retry-After header from previous response (overrides backoff)- if lastResp != nil && lastResp.statusCode == 429 {+ // Service-unavailable responses can advertise recovery time too+ // (RFC 9110 section 10.2.3). Keep the same bounded parser and budget.+ if lastResp != nil && (lastResp.statusCode == http.StatusTooManyRequests || lastResp.statusCode == http.StatusServiceUnavailable) {usedBackoff := falseif retryAfter := lastResp.headers.Get("Retry-After"); retryAfter != "" {if customBackoff, ok := parseRetryAfterBackoff(retryAfter, time.Now()); ok {@@ -352,7 +354,7 @@ func (n *NotificationManager) sendWebhookWithRetry(webhook EnhancedWebhookConfigtime.Sleep(backoff)}} else {- // Not a 429, use exponential backoff+ // No supported retry hint, use exponential backofflog.Debug().Str("webhook", webhook.Name).Int("attempt", attempt).diff --git a/internal/notifications/webhook_enhanced_test.go b/internal/notifications/webhook_enhanced_test.goindex 48f2396f00..0f4000dad0 100644--- a/internal/notifications/webhook_enhanced_test.go+++ b/internal/notifications/webhook_enhanced_test.go@@ -336,6 +336,47 @@ func TestSendWebhookWithRetry_RateLimitExhaustion(t *testing.T) {}}+// A 503 may advertise a recovery delay longer than our initial backoff.+// Observe request spacing, not merely eventual success, to detect ignored hints.+func TestSendWebhookWithRetry_ServiceUnavailableRetryAfter(t *testing.T) {+ for _, tc := range []struct {+ name string+ header string+ minimum time.Duration+ }{+ {"valid", "2", 2 * time.Second},+ {"invalid", "not-a-number", WebhookInitialBackoff},+ } {+ t.Run(tc.name, func(t *testing.T) {+ nm := NewNotificationManager("http://pulse.local")+ t.Cleanup(nm.Stop)+ require.NoError(t, nm.UpdateAllowedPrivateCIDRs("127.0.0.1"))+ attemptTimes := make(chan time.Time, 2)+ attempts := 0+ server := newIPv4HTTPServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ attempts+++ attemptTimes <- time.Now()+ if attempts == 1 {+ w.Header().Set("Retry-After", tc.header)+ w.WriteHeader(http.StatusServiceUnavailable)+ return+ }+ w.WriteHeader(http.StatusOK)+ }))+ defer server.Close()+ webhook := EnhancedWebhookConfig{+ WebhookConfig: WebhookConfig{Name: "Service recovery", URL: server.URL},+ RetryEnabled: true,+ RetryCount: 1,+ }+ require.NoError(t, nm.sendWebhookWithRetry(webhook, []byte("{}"), "service:alert"))+ require.Len(t, attemptTimes, 2)+ first, second := <-attemptTimes, <-attemptTimes+ assert.GreaterOrEqual(t, second.Sub(first), tc.minimum)+ })+ }+}+func TestSendWebhookWithRetry_429RetryAfter(t *testing.T) {nm := NewNotificationManager("http://pulse.local")_ = nm.UpdateAllowedPrivateCIDRs("127.0.0.1")@@ -891,38 +932,40 @@ func TestIsRetryableWebhookErrorEnhanced(t *testing.T) {// A response-specific zero delay must not erase backoff for later failures.func TestSendWebhookWithRetry_ZeroRetryAfterPreservesLaterBackoff(t *testing.T) {- for _, status := range []int{http.StatusServiceUnavailable, http.StatusTooManyRequests} {- t.Run(fmt.Sprint(status), func(t *testing.T) {- nm := NewNotificationManager("http://pulse.local")- t.Cleanup(nm.Stop)- require.NoError(t, nm.UpdateAllowedPrivateCIDRs("127.0.0.1"))- attemptTimes := make(chan time.Time, 3)- attempts := 0- server := newIPv4HTTPServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {- attempts++- attemptTimes <- time.Now()- switch attempts {- case 1:- w.Header().Set("Retry-After", "0")- w.WriteHeader(http.StatusTooManyRequests)- case 2:- w.WriteHeader(status)- default:- w.WriteHeader(http.StatusOK)+ for _, firstStatus := range []int{http.StatusTooManyRequests, http.StatusServiceUnavailable} {+ for _, status := range []int{http.StatusServiceUnavailable, http.StatusTooManyRequests} {+ t.Run(fmt.Sprintf("%d_then_%d", firstStatus, status), func(t *testing.T) {+ nm := NewNotificationManager("http://pulse.local")+ t.Cleanup(nm.Stop)+ require.NoError(t, nm.UpdateAllowedPrivateCIDRs("127.0.0.1"))+ attemptTimes := make(chan time.Time, 3)+ attempts := 0+ server := newIPv4HTTPServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ attempts+++ attemptTimes <- time.Now()+ switch attempts {+ case 1:+ w.Header().Set("Retry-After", "0")+ w.WriteHeader(firstStatus)+ case 2:+ w.WriteHeader(status)+ default:+ w.WriteHeader(http.StatusOK)+ }+ }))+ defer server.Close()+ webhook := EnhancedWebhookConfig{+ WebhookConfig: WebhookConfig{Name: "Backoff regression", URL: server.URL},+ RetryEnabled: true,+ RetryCount: 2,}- }))- defer server.Close()- webhook := EnhancedWebhookConfig{- WebhookConfig: WebhookConfig{Name: "Backoff regression", URL: server.URL},- RetryEnabled: true,- RetryCount: 2,- }- require.NoError(t, nm.sendWebhookWithRetry(webhook, []byte("{}"), "backoff:alert"))- require.Len(t, attemptTimes, 3)- <-attemptTimes- second, third := <-attemptTimes, <-attemptTimes- assert.GreaterOrEqual(t, third.Sub(second), 2*WebhookInitialBackoff,- "later failure must retain exponential backoff after a zero Retry-After")- })+ require.NoError(t, nm.sendWebhookWithRetry(webhook, []byte("{}"), "backoff:alert"))+ require.Len(t, attemptTimes, 3)+ <-attemptTimes+ second, third := <-attemptTimes, <-attemptTimes+ assert.GreaterOrEqual(t, third.Sub(second), 2*WebhookInitialBackoff,+ "later failure must retain exponential backoff after a zero Retry-After")+ })+ }}}