Skip to content

[Bug]: New primary is relabelled ~4 s after a switchover: instance status is retried with backoff on a definite HTTP 500 #11637

Description

@pal-salih

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 am running a supported version of CloudNativePG.

Version

1.30.1 (operator image ghcr.io/cloudnative-pg/cloudnative-pg:1.30.1, Helm chart cloudnative-pg-0.29.1)

What version of Kubernetes are you using?

1.35.7

What is your Kubernetes environment?

Cloud: Azure AKS

How did you install the operator?

Helm

What happened?

After a switchover, the new primary is labelled cnpg.io/instanceRole=primary 3.8–4.8 s after it has become status.currentPrimary. The -rw Service follows that label, so for those seconds clients behind it (PgBouncer Poolers here) have no endpoint.

From the operator's log, two reconciles happen between the promotion and the label. Each spends about 1.6–1.8 s in GetStatusFromInstances on the old primary:

  • The old primary's instance manager is up, but its PostgreSQL is stopped while it waits to come back as a replica.
  • So it answers the status request at once with HTTP 500 (failed to connect … /controller/run/.s.PGSQL.5432).
  • pkg/management/postgres/webserver/client/remote/instance.go retries that answer with backoff: 10 ms × 5ⁿ, 5 attempts, about 1.56 s.

The first of the two reconciles ends without relabelling (we suspect a status update conflict, which requeues it after 1 s; not confirmed). The second relabels (updateRoleLabels, pkg/reconciler/instance/metadata.go).

Measured across seven switchovers on 2026-10-09. All were planned switchovers of two-instance Clusters, made by setting status.targetPrimary.

Expected: a definite HTTP answer (5xx) from an instance manager is not retried; only connection-level errors are. The new primary is then relabelled within one reconcile. Fetching the instances' statuses concurrently would bound this as well.

Relevant log output

07:17:09.324 Setting primary label to unhealthy in the old primary during failover  pod=…-1
07:17:09–17  There is a switchover or a failover in progress, waiting for the operation to complete (every ~1 s)
07:17:20.299 Cannot extract Pod status  podName=…-1  error status code: 500, body: failed to connect to `user=postgres database=postgres`: /controller/run/.s.PGSQL.5432
07:17:22.114 Cannot extract Pod status  podName=…-1  (same)
07:17:22.169 Setting replica label  pod=…-1
07:17:22.208 Setting primary label  pod=…-2

The new primary was status.currentPrimary at about 07:17:18.

Code of Conduct

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

Activity

  1. io41 commented on Oct 12, 2026

    @io41

    Just found this bug while trying to figure out why switchovers are taking so long. Thanks for reporting!

  2. kabbydriver commented on Oct 13, 2026

    @kabbydriver
    Contributor

    Thanks for reporting, I think we may be looking at the same things: #11628

  3. kabbydriver commented on Oct 14, 2026

    @kabbydriver
    Contributor

    I put together a patch here: kabbydriver#1

  4. added
    bug 🐛
    on Nov 2, 2026
  5. added theissue type on Nov 2, 2026
  6. moved this to Waiting for Second Review in CloudNativePG operator developmenton Nov 2, 2026
  7. added this to the Now milestone on Nov 2, 2026
  8. moved this from Waiting for Second Review to In Second Review in CloudNativePG operator developmenton Nov 2, 2026
  9. added a commit that references this issue on Nov 2, 2026
    b45d954
  10. added a commit that references this issue on Nov 2, 2026
    6a205f0
  11. 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