Repository navigation
fix: a stuck update-state file can't hang a command - #159
Merged
Merged
Conversation
afterCommand ran the update check's Stop and the notice's LoadState with no limit whenever the clock had no parsed --timeout. A usage error such as `sel tail --bogus --timeout=1s` fails before the flag is parsed, so with the update-state file stuck (a FIFO with no writer) the process never exited. afterCommand now caps its limit at updateGrace from the moment it starts, whether or not a --timeout limit exists. An existing --timeout limit still applies when it is sooner. updateGrace is 1s. Both steps are normally milliseconds: Stop cancels the in-flight check (its own network timeout is 2s and is cut short by the cancel) and LoadState is one small file read. 1s leaves a slow disk room and keeps the whole process inside 3s with start-up. The exit code and stdout are untouched; only the abandoned update work is lost. Tests: a stuck-FIFO table (usage error before and without --timeout, a bare-group flag error, an unknown command, a valid command with and without --timeout) asserting exit code and time, plus a unit test that a wedged step is given up on at the bound for no limit and a distant limit. Both fail on the base commit by assertion or by the harness's 10s cap. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
LoadState used os.ReadFile, which opens a FIFO blocking and reads without bound. A FIFO at the state path hung `sel version` even when opted out, and any response carrying X-Selective-Cli-Latest-Version (via RecordServerHeaders) hung past the HTTP timeout. Both predate 9433d30; its updateGrace bounds the exit, not the read. Read: open with O_NONBLOCK, Stat the descriptor, treat anything not regular as no state. syscall.O_NONBLOCK exists on linux, darwin and windows, so one untagged file builds on all three. Write: saveState never opens the target, but its rename would replace a FIFO, directory or symlink. It now returns before creating the temp file unless the path is absent or a regular file. A symlinked state file is therefore still read but no longer rewritten. The Lstat-to-rename gap is not closed. Tests cover a FIFO with and without a held writer, a directory, a dangling symlink and a live symlink, plus `sel version` and a version-header response against a FIFO, asserting exit, a 3 s bound, that the FIFO was opened (inotify) and is still a FIFO. A held writer is needed to kill the read mutant: a bare nonblocking FIFO reads as EOF. The test env points HTTP(S)_PROXY at a closed port so the update check never reaches GitHub. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
natevick
marked this pull request as ready for review
November 22, 2026 21:56
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.
A FIFO or other non-regular file at the update-check state path can no longer hang a
selcommand. Before this,sel versionandsel approvals showcould block forever on it.Linear: SEL-393.
What changed
Checks
sel versionwith and without the opt-out, andsel approvals showwith a server version header, each exit promptly, 20 of 20. They fail on the commit before this fix.CI=trueandGITHUB_ACTIONS=true, and the Windows build passes.go veton all three platforms,go test -race, and golangci-lint 1.64.8 pass.Behavior to know
A symlinked state file is read but no longer saved. For that setup,
sel versionrechecks on every run, which takes up to 2 seconds on a stalled network, and a release notice learned from the server doesn't show. Other commands are unaffected.Not established
🤖 Generated with Claude Code
https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp