Repository navigation
fix(status): do not retry instance status HTTP errors - #11793
Merged
Merged
Conversation
Contributor
|
❗ By default, the pull request is configured to backport to all release branches.
|
Contributor
|
/test |
Contributor
|
@leonardoce, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/41423054414 |
Contributor
|
I believe the E2e tests are failing because they didn't manage to download an image, and this is unrelated to this PR. |
leonardoce
approved these changes
Nov 2, 2026
mnencia
approved these changes
Nov 2, 2026
Member
|
/ok-to-merge E2E green (failures are unrelated) |
Match the *StatusError returned by rawInstanceStatusRequest so HTTP errors stop immediately. Cover HTTP 500 response preservation and transient transport-error recovery through the instance-status request path. Assisted-by: OpenAI Codex Signed-off-by: Kabir Gogia <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
cnpg-bot
pushed a commit
that referenced
this pull request
Nov 2, 2026
`getReplicaStatusFromPodViaHTTP` meant to stop retrying when an instance answers with a non-200 status, but `errors.As` targeted a `StatusError` value while `rawInstanceStatusRequest` returns a `*StatusError`. It never matched, so every HTTP error used all 5 attempts (about 1.6 seconds). Pods are queried one after the other, so one failing instance delayed the whole reconcile. This showed after a switchover. The old primary answers HTTP 500 while its PostgreSQL is stopped, and each reconcile waited about 1.6 seconds on it. That delayed the primary role label on the new primary, and the `-rw` Service had no endpoint until the label moved. On kind with two instances, when the old primary answers HTTP 500, the label now follows `currentPrimary` after about 0.4 seconds instead of 3.9 (four switchovers each), and the `-rw` Service has no endpoint for about 3.1 seconds instead of 6.4 (four fixed, two baseline). The target is now `*StatusError`. HTTP errors stop after one request and keep their status code and body. Transport errors still retry and timeouts still do not, so a switchover where the old primary refuses the connection is unchanged (about 3.9 seconds before and after). A transient failure of the status probe is no longer hidden by the retry. The instance is reported as not answering right away. If it is the Ready primary, the operator logs a `PrimaryStatusCheckFailed` warning event and requeues after 10 seconds. Failover is still deferred, never triggered. Closes #11628 Closes #11637 Signed-off-by: Kabir Gogia <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]> (cherry picked from commit 6e5c680)
mnencia
pushed a commit
that referenced
this pull request
Nov 2, 2026
`getReplicaStatusFromPodViaHTTP` meant to stop retrying when an instance answers with a non-200 status, but `errors.As` targeted a `StatusError` value while `rawInstanceStatusRequest` returns a `*StatusError`. It never matched, so every HTTP error used all 5 attempts (about 1.6 seconds). Pods are queried one after the other, so one failing instance delayed the whole reconcile. This showed after a switchover. The old primary answers HTTP 500 while its PostgreSQL is stopped, and each reconcile waited about 1.6 seconds on it. That delayed the primary role label on the new primary, and the `-rw` Service had no endpoint until the label moved. On kind with two instances, when the old primary answers HTTP 500, the label now follows `currentPrimary` after about 0.4 seconds instead of 3.9 (four switchovers each), and the `-rw` Service has no endpoint for about 3.1 seconds instead of 6.4 (four fixed, two baseline). The target is now `*StatusError`. HTTP errors stop after one request and keep their status code and body. Transport errors still retry and timeouts still do not, so a switchover where the old primary refuses the connection is unchanged (about 3.9 seconds before and after). A transient failure of the status probe is no longer hidden by the retry. The instance is reported as not answering right away. If it is the Ready primary, the operator logs a `PrimaryStatusCheckFailed` warning event and requeues after 10 seconds. Failover is still deferred, never triggered. Closes #11628 Closes #11637 Signed-off-by: Kabir Gogia <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]> (cherry picked from commit 6e5c680) Signed-off-by: Marco Nenciarini <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
getReplicaStatusFromPodViaHTTPmeant to stop retrying when an instance answers with a non-200 status, buterrors.Astargeted aStatusErrorvalue whilerawInstanceStatusRequestreturns a*StatusError. It never matched, so every HTTP error used all 5 attempts (about 1.6 seconds). Pods are queried one after the other, so one failing instance delayed the whole reconcile.This showed after a switchover. The old primary answers HTTP 500 while its PostgreSQL is stopped, and each reconcile waited about 1.6 seconds on it. That delayed the primary role label on the new primary, and the
-rwService had no endpoint until the label moved. On kind with two instances, when the old primary answers HTTP 500, the label now followscurrentPrimaryafter about 0.4 seconds instead of 3.9 (four switchovers each), and the-rwService has no endpoint for about 3.1 seconds instead of 6.4 (four fixed, two baseline).The target is now
*StatusError. HTTP errors stop after one request and keep their status code and body. Transport errors still retry and timeouts still do not, so a switchover where the old primary refuses the connection is unchanged (about 3.9 seconds before and after).A transient failure of the status probe is no longer hidden by the retry. The instance is reported as not answering right away. If it is the Ready primary, the operator logs a
PrimaryStatusCheckFailedwarning event and requeues after 10 seconds. Failover is still deferred, never triggered.Closes #11628
Closes #11637
Original PR message:
Summary
Fix the
errors.Asdestination fromStatusErrorto*StatusError, matching the error returned byrawInstanceStatusRequest. Non-200 responses now stop after one request and preserve the status code/body; transient transport errors still retry.Fixes #11628
Fixes #11637
AI disclosure: OpenAI Codex assisted with investigation, code, tests, validation, and this description.
Background
A three-instance CNPG 1.30.1 rolling restart showed a 3.748-second gap between PostgreSQL readiness on the new primary and its primary role label, delaying RW routing. Meanwhile, the old primary returned HTTP 500 because its PostgreSQL socket was absent. Unnecessary retries plausibly contributed; no end-to-end improvement has been measured.
Upstream #1708 proposed broader retry/timeout changes and was closed as resolved. Current comments and the original timeout change (
ff6dd54d) explicitly exclude HTTP errors from retries. This patch leaves timeout/backoff, failover safety, and service reconciliation unchanged.Validation
Local validation on October 14, 2026 used Go 1.27.2. Regression tests use mocked RoundTrippers through the actual instance-status request path:
make test, plus uncached remote (5 specs) and PostgreSQL helper (3 specs) suites, including the previously blocked Docker image pull.BUILD_IMAGE=true OPERATOR=local FEATURE_TYPE=smoke,basic make e2e-test-kindon local Kubernetes v1.37.0: 50 passed, 0 failed, 207 skipped (205 outside the label filter; architecture and pod-patch tests skipped by default test depth). The deployed operator reported build commitc6c7b0ae. The disposable cluster was removed afterward.