Skip to content

fix(cpp): reject special input files before open to avoid FIFO hang - #977

Merged
ColinLeeo merged 2 commits into
apache:developfrom
ColinLeeo:colin/tsfile-143-fifo-hang
Oct 5, 2026
Merged

ColinLeeo merged 2 commits into
apache:developfrom
ColinLeeo:colin/tsfile-143-fifo-hang

Conversation

@ColinLeeo

Copy link
Copy Markdown
Contributor

Summary

Fixes TsFile-143: passing a FIFO (named pipe) as the TsFile input path makes tsfile-cli hang forever instead of failing fast.

Problem

tsfile-cli meta <fifo> (and ls / schema / stats / count / head / cat / sketch / export) blocks indefinitely with no output and no error.

On POSIX, open(path, O_RDONLY) on a FIFO blocks until a writer opens the other end. Since the CLI is a one-shot command with no writer, it waits forever — a script/CI caller is stuck until an external timeout kills it.

The reader already had a post-open type check (fstat + S_ISREG → E_INVALID_PATH), but that check is unreachable for FIFOs because open() itself never returns. Device files and sockets are likewise only caught after open(), where they have their own special semantics.

Requirement §3.1.2 says these special files must fail as "input problem 2" (code 37), so the current behavior both violates the contract and turns the CLI into a non-terminating process.

Fix

Preflight the path with stat() (which follows symlinks) on POSIX, before open(), mirroring the existing Windows _wstat64 preflight:

  • Non-regular files (FIFO / device / socket / directory) fail fast with E_INVALID_PATH (code 37).
  • stat() failures (missing file, dangling symlink) fall through to the normal open() path, preserving E_FILE_OPEN_ERR (code 28).
  • Symlinks resolving to regular files remain valid, as §3.1.2 permits.

The check lives in LocalRandomAccessReadFile::open, so it covers every read path (all read commands and library callers), matching the intent already documented next to the existing post-open check.

Verification

Input Before After
FIFO hangs (timeout 124) invalid path (code 37), exit 2
Directory exit 2 exit 2 (unchanged)
Dangling symlink exit 2 exit 2 (unchanged)
Regular TsFile / valid symlink exit 0 exit 0 (unchanged)

Added a FIFO regression case covering all read commands in EmptyTreeAndInputFailuresHaveExactDiagnostics.

Opening a FIFO (named pipe) read-only blocks until a writer appears, so tsfile-cli hung forever on a FIFO input instead of failing with input problem 2 (code 37). Preflight the path with stat() on POSIX before open so non-regular files (FIFO/device/socket/directory) fail fast with E_INVALID_PATH, matching the existing post-open fstat() check and the Windows preflight. Add a FIFO regression case to the read-command input-failure e2e test.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The stat/open race can still allow a substituted FIFO to block indefinitely.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Prevents POSIX FIFO and other special-file inputs from hanging TsFile readers.

Changes:

  • Adds a pre-open regular-file check.
  • Adds FIFO regression coverage across CLI read commands.
File Description
cpp/​src/​file/​local_random_access_read_file.cc Rejects non-regular inputs before opening.
cpp/​test/​tools/​model_format_e2e_test.cc Tests FIFO diagnostics for read commands.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cpp/src/file/local_random_access_read_file.cc
Added handling for O_NONBLOCK flag to close the stat/open race condition.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation prevents FIFO hangs while preserving existing handling for missing files, symlinks, and regular files.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@ColinLeeo
ColinLeeo merged commit a2b9369 into apache:develop Oct 5, 2026
39 checks passed
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.

2 participants