Skip to content

fix(fileutils): fail createFifo when an existing path is not a FIFO - #301

Merged
GabriFedi97 merged 4 commits into
mainfrom
dev/298
Jul 23, 2026
Merged

GabriFedi97 merged 4 commits into
mainfrom
dev/298

Conversation

@litaocdl

@litaocdl litaocdl commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Update the CreateFifo check logical: no-ops only if it's already a FIFO;
create the FIFO only if file not exists; fail the call if non-FIFO file exists and for other
errors.

Closes: #298

@litaocdl
litaocdl requested a review from a team July 17, 2026 10:28
@litaocdl litaocdl changed the title fix(log): update the createFifo check logical fix(log): update createFifo to use correct logical check Jul 17, 2026
@litaocdl litaocdl changed the title fix(log): update createFifo to use correct logical check fix(fileutils): fail createFifo when an existing path is not a FIFO Jul 17, 2026
@litaocdl

Copy link
Copy Markdown
Contributor Author

/test

Comment thread pkg/fileutils/compatibility/unix.go Resolved
@litaocdl
litaocdl force-pushed the dev/298 branch 2 times, most recently from b645835 to 18b432e Compare July 22, 2026 07:15
litaocdl and others added 3 commits July 23, 2026 13:19
Signed-off-by: Tao Li <[email protected]>
Signed-off-by: Gabriele Fedi <[email protected]>
Co-authored-by: Gabriele Fedi <[email protected]>
Signed-off-by: Tao Li <[email protected]>
Moving from os.Stat to os.Lstat is the one behavioral change this fix makes
against the old implementation: a symlink at the path is no longer followed,
so even a symlink that targets a genuine FIFO is reported as an error rather
than silently accepted. Pin that intent with a spec so a later switch back to
a link-following stat is caught.

Signed-off-by: Armando Ruocco <[email protected]>
CreateFifo used Lstat to check whether an existing path is already a
FIFO, but the readers that open this path (os.OpenFile, with no
O_NOFOLLOW) follow symlinks. A symlink pointing at a genuine, usable
FIFO was therefore rejected as ErrExistsNotFifo even though the reader
would have opened and streamed from it correctly.

Switch the check to Stat so it resolves the path the same way the
reader does: a symlink to a FIFO is accepted, while a symlink to a
regular file (or any other non-FIFO) is still rejected, preserving the
original fix for a stale file left where a FIFO is expected.

Signed-off-by: Armando Ruocco <[email protected]>
@GabriFedi97
GabriFedi97 merged commit 0923808 into main Jul 23, 2026
8 checks passed
@GabriFedi97
GabriFedi97 deleted the dev/298 branch July 23, 2026 14:09
mnencia added a commit to cloudnative-pg/cloudnative-pg that referenced this pull request Jul 29, 2026
…11246)

`wal-archive` and `wal-restore` run as separate `/controller/manager`
processes and are told to write their logs to `--log-destination
<LogPath>/postgres.json`, the same path the instance manager's JSON log
pipe uses for its FIFO. If one of those commands opens the destination
before the pipe has created the FIFO, `customDestination` creates a
plain regular file there (it opens with `O_CREATE`). The pipe then finds
a non-FIFO at the path; until now it silently accepted it, so the reader
opened a static file, reached EOF, and no `wal-archive`/`wal-restore`
output was ever captured. That is the silence reported in #11201.

Now that `CreateFifo` reports `ErrExistsNotFifo` for a non-FIFO, the
pipe reacts to it: it removes the stale entry and lets the next
iteration create the FIFO, so streaming recovers without operator
action. The path lives on an `emptyDir` that outlives container
restarts, so without this the only recovery is recreating the pod. The
removal is deliberately narrow: it fires only on `ErrExistsNotFifo`,
logs a warning first, and drops just the name at the path (a symlink is
removed, never its target). An in-flight writer holding the old inode
loses its buffered lines, but the next invocation opens the fresh FIFO;
that is convergent and acceptable for a transient log-staging path. The
retry loops also gain a short, cancellable backoff so a persistent
failure no longer busy-spins.

The machinery dependency is pinned (operator and e2e modules) to
machinery's `main` tip, which carries the `ErrExistsNotFifo` fix
(cloudnative-pg/machinery#301, merged) ahead of a tagged release; re-pin
to a tagged release once machinery cuts one.

Closes #11201

Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Tao Li <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Co-authored-by: Tao Li <[email protected]>
Co-authored-by: Marco Nenciarini <[email protected]>
cnpg-bot pushed a commit to cloudnative-pg/cloudnative-pg that referenced this pull request Jul 29, 2026
…11246)

`wal-archive` and `wal-restore` run as separate `/controller/manager`
processes and are told to write their logs to `--log-destination
<LogPath>/postgres.json`, the same path the instance manager's JSON log
pipe uses for its FIFO. If one of those commands opens the destination
before the pipe has created the FIFO, `customDestination` creates a
plain regular file there (it opens with `O_CREATE`). The pipe then finds
a non-FIFO at the path; until now it silently accepted it, so the reader
opened a static file, reached EOF, and no `wal-archive`/`wal-restore`
output was ever captured. That is the silence reported in #11201.

Now that `CreateFifo` reports `ErrExistsNotFifo` for a non-FIFO, the
pipe reacts to it: it removes the stale entry and lets the next
iteration create the FIFO, so streaming recovers without operator
action. The path lives on an `emptyDir` that outlives container
restarts, so without this the only recovery is recreating the pod. The
removal is deliberately narrow: it fires only on `ErrExistsNotFifo`,
logs a warning first, and drops just the name at the path (a symlink is
removed, never its target). An in-flight writer holding the old inode
loses its buffered lines, but the next invocation opens the fresh FIFO;
that is convergent and acceptable for a transient log-staging path. The
retry loops also gain a short, cancellable backoff so a persistent
failure no longer busy-spins.

The machinery dependency is pinned (operator and e2e modules) to
machinery's `main` tip, which carries the `ErrExistsNotFifo` fix
(cloudnative-pg/machinery#301, merged) ahead of a tagged release; re-pin
to a tagged release once machinery cuts one.

Closes #11201

Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Tao Li <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Co-authored-by: Tao Li <[email protected]>
Co-authored-by: Marco Nenciarini <[email protected]>
(cherry picked from commit aa196ca)
cnpg-bot pushed a commit to cloudnative-pg/cloudnative-pg that referenced this pull request Jul 29, 2026
…11246)

`wal-archive` and `wal-restore` run as separate `/controller/manager`
processes and are told to write their logs to `--log-destination
<LogPath>/postgres.json`, the same path the instance manager's JSON log
pipe uses for its FIFO. If one of those commands opens the destination
before the pipe has created the FIFO, `customDestination` creates a
plain regular file there (it opens with `O_CREATE`). The pipe then finds
a non-FIFO at the path; until now it silently accepted it, so the reader
opened a static file, reached EOF, and no `wal-archive`/`wal-restore`
output was ever captured. That is the silence reported in #11201.

Now that `CreateFifo` reports `ErrExistsNotFifo` for a non-FIFO, the
pipe reacts to it: it removes the stale entry and lets the next
iteration create the FIFO, so streaming recovers without operator
action. The path lives on an `emptyDir` that outlives container
restarts, so without this the only recovery is recreating the pod. The
removal is deliberately narrow: it fires only on `ErrExistsNotFifo`,
logs a warning first, and drops just the name at the path (a symlink is
removed, never its target). An in-flight writer holding the old inode
loses its buffered lines, but the next invocation opens the fresh FIFO;
that is convergent and acceptable for a transient log-staging path. The
retry loops also gain a short, cancellable backoff so a persistent
failure no longer busy-spins.

The machinery dependency is pinned (operator and e2e modules) to
machinery's `main` tip, which carries the `ErrExistsNotFifo` fix
(cloudnative-pg/machinery#301, merged) ahead of a tagged release; re-pin
to a tagged release once machinery cuts one.

Closes #11201

Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Tao Li <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Co-authored-by: Tao Li <[email protected]>
Co-authored-by: Marco Nenciarini <[email protected]>
(cherry picked from commit aa196ca)
mnencia added a commit to cloudnative-pg/cloudnative-pg that referenced this pull request Jul 29, 2026
…11246)

`wal-archive` and `wal-restore` run as separate `/controller/manager`
processes and are told to write their logs to `--log-destination
<LogPath>/postgres.json`, the same path the instance manager's JSON log
pipe uses for its FIFO. If one of those commands opens the destination
before the pipe has created the FIFO, `customDestination` creates a
plain regular file there (it opens with `O_CREATE`). The pipe then finds
a non-FIFO at the path; until now it silently accepted it, so the reader
opened a static file, reached EOF, and no `wal-archive`/`wal-restore`
output was ever captured. That is the silence reported in #11201.

Now that `CreateFifo` reports `ErrExistsNotFifo` for a non-FIFO, the
pipe reacts to it: it removes the stale entry and lets the next
iteration create the FIFO, so streaming recovers without operator
action. The path lives on an `emptyDir` that outlives container
restarts, so without this the only recovery is recreating the pod. The
removal is deliberately narrow: it fires only on `ErrExistsNotFifo`,
logs a warning first, and drops just the name at the path (a symlink is
removed, never its target). An in-flight writer holding the old inode
loses its buffered lines, but the next invocation opens the fresh FIFO;
that is convergent and acceptable for a transient log-staging path. The
retry loops also gain a short, cancellable backoff so a persistent
failure no longer busy-spins.

The machinery dependency is pinned (operator and e2e modules) to
machinery's `main` tip, which carries the `ErrExistsNotFifo` fix
(cloudnative-pg/machinery#301, merged) ahead of a tagged release; re-pin
to a tagged release once machinery cuts one.

Closes #11201

Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Tao Li <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Co-authored-by: Tao Li <[email protected]>
Co-authored-by: Marco Nenciarini <[email protected]>
(cherry picked from commit aa196ca)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CreateFifo doesn't check that an existing path is actually a FIFO before treating it as already set up

4 participants