Skip to content

[Bug]: Instance-status HTTP errors incorrectly consume all retry attempts #11628

Description

@kabbydriver

Is there an existing issue already for this bug?

  • I have searched for an existing issue, and could not find anything. I believe this is a new bug.

I have read the troubleshooting guide

  • I have read the troubleshooting guide and I think this is a new bug.

I am running a supported version of CloudNativePG

  • I have read the troubleshooting guide and I think this is a new bug.

Contact Details

[email protected]

Version

1.30 (latest patch)

What version of Kubernetes are you using?

1.37

What is your Kubernetes environment?

Cloud: Amazon EKS

How did you install the operator?

Helm

What happened?

This investigation was primarily done and documented with AI.

While investigating a rolling restart of a three-instance CloudNativePG
1.30.1 cluster, we found a pointer/value mismatch in the instance-status
HTTP retry logic. The mismatch is also present on current main.

In pkg/management/postgres/webserver/client/remote/instance.go,
rawInstanceStatusRequest returns *StatusError for a non-200 response.
However, getReplicaStatusFromPodViaHTTP checks:

var statuserror StatusError
if errors.As(err, &statuserror) {
    return false
}

The destination holds a StatusError value, so it does not match the
returned *StatusError. Consequently, HTTP status errors take the retry
path and consume all five attempts.

Expected behavior: a non-200 HTTP response should stop immediately,
consistent with the existing comment and retry predicate. Transient
transport errors should continue to retry.

We independently reproduced this with a unit test using a mocked HTTP
transport through the actual getReplicaStatusFromPodViaHTTP path:

  • HTTP 500: expected one request, observed five before the fix.
  • Changing the declaration to var statuserror *StatusError makes the
    test pass with one request.
  • A separate test confirms that a transient transport error still retries
    and succeeds on the second request.
  • The complete remote package suite passes after the fix.

Operational context: during the rolling restart, PostgreSQL on the new
primary became ready at 15:03:01.304, while the operator applied its primary
role label at 15:03:05.052—a 3.748-second gap delaying RW service routing.
During this interval, the old primary's /pg/status returned HTTP 500
because its PostgreSQL socket was absent.

The unnecessary retries plausibly contributed to that delay, but this
timing attribution is an inference. We have not measured an end-to-end
improvement after deploying the fix.

Proposed change: correct the errors.As destination type and add regression
tests for HTTP-error termination and transient transport-error recovery.
No timeout, failover-safety, or service-reconciliation changes are proposed.

Cluster resource

Relevant log output

22:02:58.481  operator  "The primary needs to be restarted, we'll trigger a switchover to do that"
                       currentPrimary=core-db-1 targetPrimary=core-db-3
                       reason="cluster has been explicitly restarted via annotation"

22:02:58.719  core-db-1 "received fast shutdown request"

22:02:58.737  operator  "Setting primary label to unhealthy in the old primary during failover"
                       pod=core-db-1

22:03:00.834  core-db-3 "received promote request"

22:03:01.304  core-db-3 "database system is ready to accept connections"

22:03:03.203  operator  "Cannot extract Pod status"
                       podName=core-db-1
                       error="error status code: 500, body: failed to connect to
                       `user=postgres database=postgres`: /controller/run/.s.PGSQL.5432
                       (/controller/run): dial error: dial unix
                       /controller/run/.s.PGSQL.5432: connect: no such file or directory"

22:03:04.999  operator  "Cannot extract Pod status"
                       podName=core-db-1
                       [same HTTP 500 / missing PostgreSQL socket error]

22:03:05.051  operator  "Setting primary label"
                       pod=core-db-3

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    bug 🐛
    triage
    on Oct 8, 2026
  2. kabbydriver commented on Oct 8, 2026

    @kabbydriver
    ContributorAuthor

    I'd like to work on this.

    Proposed fix:

    diff --git a/pkg/management/postgres/webserver/client/remote/instance.go b/pkg/management/postgres/webserver/client/remote/instance.go
    --- a/pkg/management/postgres/webserver/client/remote/instance.go
    +++ b/pkg/management/postgres/webserver/client/remote/instance.go
    @@ -157,7 +157,7 @@ func (r *instanceClientImpl) getReplicaStatusFromPodViaHTTP(
     		}
    
     		// If the pod answered with a not ok status, it is pointless to retry
    -		var statuserror StatusError
    +		var statuserror *StatusError
     		if errors.As(err, &statuserror) {
     			return false
     		}
    
  3. kabbydriver commented on Oct 14, 2026

    @kabbydriver
    ContributorAuthor

    The patch is ready for review: kabbydriver#1
    Regression tests confirm five HTTP requests before the fix and one afterward, while preserving transport retries. Local unit tests and 50 smoke/basic E2E specs passed using the patched operator. Could you confirm the approach and assign the issue to me?

  4. pal-salih commented on Oct 20, 2026

    @pal-salih

    We hit the same bug independently and reported it with switchover timings in #11637: across seven planned switchovers on 1.30.1, the new primary got its instanceRole=primary label 3.8–4.8 s after becoming currentPrimary, and each of the two reconciles in between spent about 1.6 s retrying the old primary's HTTP 500. The one-line fix in kabbydriver#1 (StatusError → *StatusError) matches what we found.

    @kabbydriver is ready to open the PR and is waiting for assignment. Could a maintainer confirm the approach and assign this issue?

  5. kabbydriver commented on Oct 22, 2026

    @kabbydriver
    ContributorAuthor

    @gbartolini would you mind taking a look?

  6. removed
    triage
    on Nov 2, 2026
  7. added theissue type on Nov 2, 2026
  8. moved this to Waiting for Second Review in CloudNativePG operator developmenton Nov 2, 2026
  9. added this to the Now milestone on Nov 2, 2026
  10. moved this from Waiting for Second Review to In Second Review in CloudNativePG operator developmenton Nov 2, 2026
  11. added a commit that references this issue on Nov 2, 2026
    b45d954
  12. added a commit that references this issue on Nov 2, 2026
    6a205f0
  13. added a commit that references this issue on Nov 2, 2026
    6e5c680
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug 🐛

Type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions