Skip to content

[Bug]: Replica can remain healthy after unrecoverable WAL replay loop #11134

Open

Description

@ardentperf

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.0

What version of Kubernetes are you using?

1.36

What is your Kubernetes environment?

Cloud: Azure AKS

How did you install the operator?

YAML manifest

What happened?

A replica can enter an unrecoverable WAL replay failure loop while CNPG continues to treat the instance as healthy enough for normal operation. In this state the instance repeatedly logs WAL replay errors at the same LSN, but the operator does not get a hard status signal from the instance manager.

Reproducer: https://github.com/ardentperf/bug-repro-wal-restore

Observed impact:

  • the broken replica becomes Ready even though WAL replay is stuck
  • the pod remains eligible for read traffic through normal service endpoints
  • the replica remains a possible failover/promotion target because /pg/status does not report an error
  • diagnosis currently depends on inspecting instance logs directly

Expected behavior:

When the instance manager detects repeated unrecoverable WAL replay errors with no replay progress, it should mark the instance unhealthy through existing readiness and status paths. CNPG should stop routing traffic to the replica and existing target-selection logic should avoid it.

Known log patterns include:

  • record with incorrect prev-link ... at ...
  • contrecord is requested by ...

A future enhancement may be useful to surface "user action needed" conditions directly on the Cluster object, but operator and instance logs are sufficient for the initial fix.

Cluster resource

Relevant log output

Code of Conduct

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

Activity

  1. added
    bug 🐛
    triage
    on Jul 6, 2026
  2. dosubot commented on Jul 6, 2026

    @dosubot

    This is a well-documented report and aligns with a pattern of related issues that have been surfaced in production environments.

    Confirming the gap: The codebase collects the relevant WAL replay metrics (ReplayLsn, ReceivedLsn, IsWalReceiverActive) and exposes them via /pg/status, but these values are only consulted during switchover/promotion target selection — not for continuous replica health assessment [1] [2]. A replica whose WAL replay is looping at a fixed LSN will still return HTTP 200 from /pg/status and pass readiness checks as long as it can respond to read-only queries [3].

    No existing detection for stuck replay: There is no operator-level logic that parses specific PostgreSQL WAL replay errors (like record with incorrect prev-link or contrecord is requested by) or tracks LSN stalls over time to mark an instance unhealthy [4].

    Related prior incidents:

    For the readiness side of this issue, one approach would be to have the instance manager track ReplayLsn across reconciliation cycles (or probe intervals) and mark the instance unhealthy via readiness when the LSN is not advancing despite PostgreSQL being in recovery. The failover target selection code already sorts replicas by LSN and excludes instances with status errors [5], so marking the instance with an error in its status response would automatically exclude it from promotion without requiring new failover logic.

    This would pair nicely with your earlier pg_controldata-based progress signal proposal from #11024 — that one solves "don't kill a replica that IS making progress" while this issue is about "do mark a replica that ISN'T making progress."

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about cloudnative-pg with Dosu Add Dosu to your team

  3. github-actions commented on Oct 14, 2026

    @github-actions
    Contributor

    This issue is stale because it has been open for 60 days with no activity.

  4. ardentperf commented on Oct 20, 2026

    @ardentperf
    ContributorAuthor

    I'm not sure if this is addressed yet. need to review

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

Metadata

Metadata

Assignees

Labels

bug 🐛triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions