Skip to content

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

Open
ColinLeeo wants to merge 1 commit into
apache:developfrom
ColinLeeo:colin/tsfile-143-fifo-hang
Open

ColinLeeo wants to merge 1 commit 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.
@ColinLeeo
ColinLeeo force-pushed the colin/tsfile-143-fifo-hang branch from 499dda9 to 08d61c3 Compare September 30, 2026 10:05
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.

1 participant