Skip to content

fix: exit 0 when a downstream reader closes stdout early#1811

Open
varuntej07 wants to merge 1 commit into
Graphify-Labs:v8from
varuntej07:fix-broken-pipe-exit
Open

fix: exit 0 when a downstream reader closes stdout early#1811
varuntej07 wants to merge 1 commit into
Graphify-Labs:v8from
varuntej07:fix-broken-pipe-exit

Conversation

@varuntej07

Copy link
Copy Markdown

Problem

Piping graphify into a reader that stops early (head, PowerShell
Select-Object -First N, a pager that quits) closes stdout before we finish
writing. The interpreter's shutdown flush then hits the closed pipe and crashes:

Exception ignored on flushing sys.stdout:
OSError: [Errno 22] Invalid argument

The process exits nonzero (120 on POSIX). A downstream head closing the pipe
is normal, so graphify should exit 0 the way foo | head does.

Fix

Wrap the CLI entry point: catch BrokenPipeError and OSError with EINVAL or
EPIPE (Windows reports a closed pipe as EINVAL), redirect stdout to devnull
so the shutdown flush stays quiet, and exit 0. Unrelated OSErrors still
propagate, so real failures such as a missing graph.json are not masked.

Verification

A reader that reads one line then closes the pipe:

before: returncode=120, "Exception ignored on flushing sys.stdout"
after:  returncode=0,   clean

Adds tests/test_broken_pipe_exit.py (5 tests covering the exit-code contract,
including that non-pipe errors still propagate). Existing CLI suites pass.

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