Skip to content

fix: a stuck update-state file can't hang a command - #159

Merged
natevick merged 3 commits into
mainfrom
natevick/sel-393-update-hang
Nov 22, 2026
Merged

natevick merged 3 commits into
mainfrom
natevick/sel-393-update-hang

Conversation

@natevick

Copy link
Copy Markdown
Contributor

A FIFO or other non-regular file at the update-check state path can no longer hang a sel command. Before this, sel version and sel approvals show could block forever on it.

Linear: SEL-393.

What changed

  • Reading state opens the file without blocking and treats anything but a regular file as no state.
  • Writing state is skipped unless the path is absent or a regular file. A FIFO is never replaced or deleted.
  • The update step after a command is capped at one second.

Checks

  • FIFO at the state path: sel version with and without the opt-out, and sel approvals show with a server version header, each exit promptly, 20 of 20. They fail on the commit before this fix.
  • The FIFO is still a FIFO afterward, and the tests prove it was opened.
  • A directory or dangling symlink at the path keeps the normal exit code.
  • Removing the read check or the write check fails tests.
  • The hang tests also pass with CI=true and GITHUB_ACTIONS=true, and the Windows build passes.
  • go vet on 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 version rechecks 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

  • macOS and Windows were only vetted and built for this change.
  • The path could change between the file check and the rename.

🤖 Generated with Claude Code

https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp

Nate Vick and others added 3 commits November 22, 2026 11:20
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
natevick marked this pull request as ready for review November 22, 2026 21:56
@natevick
natevick merged commit 99149b0 into main Nov 22, 2026
1 check passed
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