fix: make signal handlers async-signal-safe#25
Open
rmorgans wants to merge 6 commits intomobydeck:mainfrom
Open
fix: make signal handlers async-signal-safe#25rmorgans wants to merge 6 commits intomobydeck:mainfrom
rmorgans wants to merge 6 commits intomobydeck:mainfrom
Conversation
Extract write_all() and use it everywhere a socket write must be complete-or-fail. Fixes spurious disconnects under memory pressure or signal interruption that returns a short count. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
send_kill() still used a bare write() for the kill packet. Apply the same write_all() retry loop as push and attach paths. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- write_all: return -1 with errno=EIO when write() returns 0 (no progress), preventing an infinite retry loop - Include fault injection tests (preload_short_write.c) that force short socket writes to deterministically verify the retry logic in push and kill paths Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace printf/exit in signal handlers with volatile sig_atomic_t flags. Use sigaction() instead of signal() to control SA_RESTART explicitly: SA_RESTART for SIGWINCH (benign), no SA_RESTART for fatal signals so select() returns EINTR promptly. Handle EINTR in read paths. write_all() stops retrying EINTR when die_signal is set. When stdout itself is wedged (blocked write to PTY), the deferred-signal exit path uses TCSANOW + _exit() to avoid hanging in printf or atexit handlers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
C harness using forkpty() for exact PID targeting — no pkill races or heuristic process identification. Tests SIGWINCH survival, SIGTERM exit, SIGHUP exit, SIGTERM during blocked stdout write, and detach character. Wire harness into test.sh with TAP folding that preserves diagnostic lines for debuggability. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
rmorgans
added a commit
to rmorgans/atch
that referenced
this pull request
Mar 15, 2026
… blocked-write fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
printf/exitin signal handlers withvolatile sig_atomic_tflags (async-signal-safe)sigaction()instead ofsignal()with explicitSA_RESTARTcontrol: enabled for SIGWINCH, disabled for fatal signals soselect()returns EINTR promptlywrite_all()stops retrying EINTR whendie_signalis set, and the exit path usesTCSANOW+_exit()when stdout is wedgedforkpty()-based signal safety integration tests with exact PID targeting*.dSYM/to.gitignoreDependency
This branch is stacked on #22 (
fix/write-all). The first 3 commits belong to that PR. Merge #22 first, then this PR will be a clean 3-commit diff.Test plan
sh tests/test_signal.sh ./atch— 12 passed, 0 failedsh tests/test.sh ./atch— signal cases pass; one pre-existing unrelated failure (dash in binary name)yes Xsession, don't drain PTY, send SIGTERM — exits within 1s (previously hung forever)🤖 Generated with Claude Code