Skip to content

feat(ver-check): add timeout flag to prevent hanging on unresponsive binaries#289

Open
rawlingsj wants to merge 1 commit intochainguard-dev:mainfrom
rawlingsj:ver-check-timeout
Open

feat(ver-check): add timeout flag to prevent hanging on unresponsive binaries#289
rawlingsj wants to merge 1 commit intochainguard-dev:mainfrom
rawlingsj:ver-check-timeout

Conversation

@rawlingsj
Copy link
Member

@rawlingsj rawlingsj commented Jan 29, 2026

Summary

  • Adds --timeout=SECONDS flag (default: 5s) to prevent ver-check from hanging indefinitely when binaries don't respond to version flags
  • Implements cross-platform timeout support (uses timeout command on Linux, shell-based fallback on macOS)
  • During auto-detection, timed-out flags are skipped and the next flag is tried
  • With explicit --version-flag, a timeout results in a clear failure message

Fixes

Discovered in this presubmit https://github.com/chainguard-dev/stereo/pull/14158

~ # ver-check '--bins=livenessprobe' '--version=2.10.0' '--version-flag=auto' '--match-type=contains' '--verbose=false'
INFO[ver-check]: Starting version checks for: livenessprobe
INFO[ver-check]: Expected version: 2.10.0
INFO[ver-check]: Match type: contains
INFO[ver-check]: Version flag: auto
^C
~ # livenessprobe version
^C

There is no version command, the process is started and therefore hangs.

Test plan

  • Verified --help shows new --timeout option
  • Tested with working binary (git) - passes as expected
  • Tested with hanging script - properly times out after configured duration instead of hanging indefinitely
  • Timeout info displayed in startup messages

🤖 Generated with Claude Code

…binaries

When checking binaries that don't support version flags (like livenessprobe),
ver-check would hang indefinitely waiting for the command to complete.

This adds a --timeout flag (default: 5 seconds) that limits how long each
version command can run. The implementation:

- Uses the `timeout` command when available (Linux)
- Falls back to a shell-based timeout using background processes (macOS)
- Returns exit code 124 on timeout (matching `timeout` convention)
- During auto-detection, skips to the next flag on timeout
- With explicit flags, fails with a clear timeout error message

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Contributor

@smoser smoser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to change the pipeline also (in pipelines/) to let the caller set -timeout?

shift
if command -v timeout >/dev/null 2>&1; then
timeout "$secs" "$@" 2>&1
return $?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its fine to check to see if this is available, but is there any reason not to add a dependency on coreutils to the package.

version_flag="auto"
match_type="contains"
VERBOSE=false
timeout_secs=5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might as well bump this up to 10 or 30. The only thing you want it to catch is "command will never return", not "command is just slow or system is heavily loaded, but it would have returned correctly in 15 seconds".

timeout "$secs" "$@" 2>&1
return $?
fi
# Fallback for systems without timeout command (e.g., macOS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you actually running this on non-linux somewhere?

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.

2 participants