Skip to content

[Bug]: wal-archive/wal-restore log destination can be silently and permanently downgraded from a FIFO to a dead regular file #11201

Description

@mnencia

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

No response

Version

trunk (main)

What version of Kubernetes are you using?

1.34

What is your Kubernetes environment?

Self-managed: kind (evaluation)

How did you install the operator?

YAML manifest

What happened?

wal-archive and wal-restore (invoked by PostgreSQL as archive_command/restore_command, and by pg_rewind --restore-target-wal) are given --log-destination <path> pointing at a path the instance manager expects to be a FIFO, tailed by a logpipe.LineLogPipe reader and converted into the structured JSON stream visible in kubectl logs. Creating that FIFO is conditional: it only happens if the path doesn't already exist (that check lives in cloudnative-pg/machinery; see cloudnative-pg/machinery#298). Nothing in cloudnative-pg/cloudnative-pg ever confirms the FIFO actually exists before code that could write to that path runs.

Two places start these readers, and neither synchronizes on their readiness. pkg/management/postgres/instance.go's WithActiveInstance (bootstrap only, used by initdb.go/restore.go) launches the readers as bare goroutines and calls instance.Startup() right after, with no wait in between; its own comment describes the hazard ("Without these readers nothing calls Mkfifo on the log paths, the writers fall back to creating regular files, and their log output is silently lost"), but starting the goroutines a few statements earlier only narrows the window, it doesn't close it. LineLogPipe exposes a condition (GetExecutedCondition()) that's broadcast right after the FIFO is created, which is exactly what a caller would wait on to close this window, but no caller anywhere in the codebase does. The steady-state path, internal/cmd/manager/instance/run/cmd.go, has an even wider opportunity: it registers the same readers and the InstanceReconciler as independent controller-runtime Runnables via separate mgr.Add(...) calls, with substantially more setup code in between and no ordering at all.

Losing that race even once is enough to break log capture for the path's entire remaining lifetime, not just for the one invocation that raced. postgres.LogPath lives under ScratchDataDirectory (/controller), backed by the pod's scratch-data EmptyDir volume, which survives container restarts and is only wiped when the pod itself is deleted and recreated. Nothing in the codebase cleans that directory on a container restart. So once any writer creates a plain file at the log-destination path instead of a FIFO (whether during this pod's original bootstrap or any subsequent restart), it stays a plain file across every later restart of that same pod, because the FIFO-creation check never revisits a path that already exists.

This matches a real incident: a demoted former primary running pg_rewind --restore-target-wal failed 22 times in a row with could not restore file ... from archive while walking backward through WAL, and every one of those wal-restore invocations produced zero log lines in the captured JSON stream for the entire ~45-minute window, which is more consistent with a log destination that was already a dead regular file than with a race being freshly lost partway through. I haven't been able to independently confirm exactly when in that pod's history the path was first corrupted, only that the mechanism described above would produce exactly this symptom and that nothing in the code would ever self-heal it once it happened.

I'd expect the log-destination path to be verified as a real FIFO, not just as "some file exists here," before anything is allowed to write to it, and for that verification to happen on every restart rather than being skippable once a stale file is present from an earlier one.

Related: cloudnative-pg/machinery#298 (CreateFifo doesn't validate an existing path is actually a FIFO) and cloudnative-pg/machinery#299 (log-destination open flags overwrite instead of appending), both surfaced by this same investigation.

Cluster resource

(code-analysis finding, not tied to a specific cluster spec)

Relevant log output

(representative symptom: zero "logger":"wal-restore" JSON lines in the captured pod logs despite repeated invocations)

Code of Conduct

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

Activity

  1. added
    bug 🐛
    triage
    on Jul 15, 2026
  2. removed
    triage
    on Jul 15, 2026
  3. added theissue type on Jul 15, 2026
  4. Utkarsh-sharma47 commented on Jul 16, 2026

    @Utkarsh-sharma47
    Contributor

    I'd like to investigate this issue. I'll report back with my findings once I've traced the relevant code paths.
    if noone is working on this i would like to do.

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

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions