fix: prevent SIGPIPE from killing process when subprocess ignores stdin (fixes #25)#26
Conversation
Change SIGPIPE handler from SIG_DFL to SIG_IGN to prevent silent exit 141 when shell nodes don't consume all their stdin data. Root cause: When a subprocess (e.g., `echo '[]'`) doesn't read its stdin, and the parent process has >16KB of data to write, SIGPIPE is sent when the subprocess exits. With SIG_DFL, this immediately terminates Python with no error message, no trace file, complete silence. With SIG_IGN, subprocess.run() handles broken pipes gracefully internally. Includes: - 9 unit tests for shell node SIGPIPE handling - 7 integration tests for workflow-level regression - Updated pitfalls.md with corrected SIGPIPE guidance Fixes #25
Code Review - PR #26: SIGPIPE FixOverall Assessment: ✅ APPROVED - Excellent bug fix with outstanding test coverage and documentation. This PR fixes a critical silent failure bug (exit 141) with a minimal, surgical one-line change backed by comprehensive testing and stellar documentation. The fix is correct, the tests are well-designed, and the knowledge capture is exemplary. Critical — must fix before mergeNone - This PR is ready to merge as-is. Warnings — should be addressed1. Minor: Test file docstring references
|
Summary
Fixes a critical bug where shell nodes would cause silent exit 141 when the subprocess doesn't consume all its stdin data. This happened when:
echo '[]'in a conditional branch)SIG_DFL, which immediately terminates PythonRoot Cause
The signal handler
signal.signal(signal.SIGPIPE, signal.SIG_DFL)caused Python to terminate with exit 141 whensubprocess.run()tried to write to a pipe that was closed because the subprocess exited without consuming stdin.Example trigger: A workflow with conditional shell logic:
The Fix
Change
SIG_DFLtoSIG_IGN:With
SIG_IGN,subprocess.run()handles broken pipes gracefully internally.Changes
src/pflow/cli/main.pySIG_DFL→SIG_IGNwith detailed commenttests/test_nodes/test_shell/test_shell_sigpipe.pytests/test_integration/test_sigpipe_regression.py.taskmaster/knowledge/pitfalls.mdTesting
Test Coverage
The tests verify:
head -n 1)FalseSIG_IGNVerified the tests catch regression
Fixes #25