Skip to content

[Bug]: primary isolation check restarts a healthy primary when only ONE replica is unreachable (docs: "cannot reach any other instance") #11641

Open

Description

@delyanlilovbiz-wq

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.

(#11280 is related — an isolated primary that keeps accepting writes — but it is the opposite case.)

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

  • Yes.

Version

1.30 (operator ghcr.io/cloudnative-pg/cloudnative-pg:1.30.1)

What version of Kubernetes are you using?

1.36

What is your Kubernetes environment?

Self-managed: RKE2

How did you install the operator?

Helm

What happened?

With the primary isolation check enabled (the default since 1.27, requestTimeout/connectionTimeout 1000 ms), the loss of a
node that hosted one replica restarted the healthy primary on another node. Every client lost the database for about
21 s, and there was no failover — the same pod came back as primary. Nothing was gained.

The documentation (docs/src/instance_manager.md, "Primary Isolation") says the liveness probe of a primary fails if both
"the instance manager cannot reach the Kubernetes API server" and "the instance manager cannot reach any other instance";
the note below it speaks of "a primary that has lost connectivity to both the API server and the other instances":
https://github.com/cloudnative-pg/cloudnative-pg/blob/v1.30.1/docs/src/instance_manager.md#L226-L245

The code fails the probe as soon as one instance in the last known InstancesReportedState is unreachable —
ensureInstancesAreReachable returns the first ping error:
https://github.com/cloudnative-pg/cloudnative-pg/blob/v1.30.1/pkg/management/postgres/webserver/probes/pinger.go#L104-L114
called from IsHealthy when the API server could not be reached:
https://github.com/cloudnative-pg/cloudnative-pg/blob/v1.30.1/pkg/management/postgres/webserver/probes/liveness.go#L91-L116

So when a replica's node dies and, at the same time, the API server does not answer the primary within 1 s for ~30 s (here an API
server endpoint was on the lost node), the primary — which can still reach the other replica — reports itself isolated and is
killed by the kubelet after failureThreshold (3 × 10 s).

Expected: an unreachable replica should not make a primary "isolated" while it can still reach another instance — i.e. fail
only if NO other instance is reachable, as documented (or by a majority rule). A sketch:

func (e pinger) ensureInstancesAreReachable(cluster *apiv1.Cluster) error {
	var lastErr error
	for name, state := range cluster.Status.InstancesReportedState {
		if string(name) == cluster.Status.CurrentPrimary {
			continue // ourselves
		}
		if err := e.ping(string(name), state.IP); err != nil {
			lastErr = err
			continue
		}
		return nil // at least one other instance answers: not isolated
	}
	return lastErr
}

Workaround: spec.probes.liveness.isolationCheck.enabled: false (applied; the instance manager picks it up live, no rollout).

Cluster resource

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
spec:
  instances: N              # N >= 2: one primary, asynchronous streaming replicas on other nodes
  imageName: ghcr.io/cloudnative-pg/postgresql:16.15
  primaryUpdateStrategy: unsupervised
  smartShutdownTimeout: 10
  # probes: defaults at the time (isolationCheck enabled, requestTimeout/connectionTimeout 1000, livenessProbeTimeout 30)

Relevant log output

The primary's instance manager (a replica's node powered off at ~22:04:20Z):

22:04:24.609 Instance connectivity error - liveness probe failing
22:04:25.919 readiness probe using cached cluster definition due to API server connectivity issue
22:04:34.608 Instance connectivity error - liveness probe failing
22:04:35.920 readiness probe using cached cluster definition due to API server connectivity issue
22:04:44.609 Instance connectivity error - liveness probe failing
22:04:44.617 Requesting smart shutdown of the PostgreSQL instance
22:04:54.653 Requesting fast shutdown of the PostgreSQL instance

Events of the primary's pod:

22:04:44Z Unhealthy: Liveness probe failed: HTTP probe failed with statuscode: 500
22:04:44Z Killing: Container postgres failed liveness probe, will be restarted
22:05:05Z Started: Container started

Clients saw FATAL: terminating connection due to administrator command at 22:05:05Z.

Code of Conduct

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

Activity

  1. AhmedShaltout commented on Oct 25, 2026

    @AhmedShaltout

    Another occurrence on 1.30.1, with one extra detail that makes the API leg of the predicate fire on a fault elsewhere in the cluster.

    Setup: 3 instances, one per site across 3 sites, synchronous: {method: any, number: 1, failoverQuorum: true}, failoverDelay: 60, default liveness (10 s × 3) and default isolation check (1000/1000 ms). k3s with 5 apiservers, each talking only to its local etcd member.

    What happened:

    • About 60 s of gray packet loss hit one control-plane node: lossy and slow, but up. Its etcd member stalled on linearizable reads, with one read blocked for 10.6 s, so that node's apiserver answered slowly (p99 7.5–14.6 s). The other 4 apiservers stayed normal.
    • The primary ran on a different node. Its instance manager's API client was on an established connection to the degraded node's apiserver. The apiserver audit log shows its lease Txn going through that node's etcd at the start of the fault, and its Secret GETs still arriving at that apiserver 57 s later, just before the restart. Dropping the node from the default/kubernetes endpoints twice in between did not move the connection.
    • One replica of that cluster lived on the degraded node.
    • So both legs failed at once. The Cluster GET exceeded the hard-coded 500 ms (cache.go), and /failsafe to that one replica timed out at 1000 ms, while the primary could reach the other replica and 4 of 5 apiservers.
    • The probe logged Instance connectivity error - liveness probe failing at +10/+20/+30 s with apiServerReachable:false and the error naming the one replica. The kubelet sent SIGTERM 8 ms after the third failure. Smart shutdown, then fast shutdown and an in-place restart followed, with no failover. Clients lost the database for about 24 s, and it all started after the network fault had already cleared.
    • A second cluster's primary, with the same pinning and a replica on the same node, failed the check twice and survived by about 2.4 s.

    Why this matters beyond the "ANY peer" semantics in this issue: with instances spread across sites, every primary has a peer on any given failing node, and its API connection lands on that node's apiserver about 1/N of the time. The two legs of the predicate are therefore not independent evidence of isolation. One sick node can satisfy both.

    Requests, in addition to fixing the "any other instance" semantics described above:

    1. Fence only when a majority of the peers in InstancesReportedState is unreachable, not on the first failed ping.
    2. Retry the API leg on a fresh connection, or against another endpoint, before treating it as unreachable. The 500 ms GET on a long-lived pinned connection measures one apiserver, not reachability of the API.

    Raising livenessProbeTimeout would have masked this one, but it can't go above failoverDelay without risking two primaries, so the fix needs to be in the predicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions