ci-watchdog

command
v0.17.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Command ci-watchdog runs one CI step under the job's clock, so a hang fails with a goroutine dump before the job's cap cancels it with none.

go test's -timeout counts from each test binary's own start, so a package that starts late in a long step meets the job's timeout-minutes first, and a cancellation at the cap carries nothing but the cancellation. ci.yml's check job and macos-suite.yml's shard job therefore run every step that runs go test with

shell: go run ./cmd/ci-watchdog bash --noprofile --norc -eo pipefail {0}

It starts the command as a process group of its own and, at the job's start plus its cap less its margin, sends SIGQUIT to the test binaries: the processes in that group whose parent is go test, a child of the shell. On SIGQUIT each test binary prints every goroutine's stack and exits, and go test prints that output with the package's FAIL line. go test itself is never sent it: it takes SIGQUIT for an interrupt, stops scheduling work, and drops the output it holds for each package of a run that names several, so a SIGQUIT to the whole group loses the dumps. Each target is chosen from ps by the group's id and its parent, never by its own name, and its group and parent are read again just before its signal. After a grace period the watchdog sends the whole group SIGKILL through the step's own handle, checked again just before: the group's leader must still be this watchdog's child, not yet waited for, and still lead its group. A SIGINT or SIGTERM sent to the watchdog itself is passed on to the group the same way. Started through go run, as ci.yml starts it, the runner's cancellation does not reach it: go run ignores SIGINT and dies on SIGTERM without passing either on, so the step's group is left to the runner's clean-up of the job's orphan processes when the job ends. If no child of the shell is go at the deadline (a step whose shell ran its last command in its own place, say), there is nothing to send SIGQUIT to: the watchdog says what it found instead and sends the group SIGKILL at once, so that step fails loudly rather than with no dump and no word why.

A target's pid is signalled on its own, not through a handle: between the last read of its group and parent and its signal, the process can exit and its pid be reused. The read just before narrows that window to a new process that took the same pid and joined the step's own group under the same parent, which only the step's own processes can do.

It reads the job's clock from the environment those jobs set: ABCD_CI_LEG (the leg it names), ABCD_CI_JOB_STARTED (the job's start in Unix seconds, exported by the "Record the job's start" step), ABCD_CI_JOB_CAP_MINUTES (the leg's timeout-minutes) and ABCD_CI_WATCHDOG_MARGIN_MINUTES (the workflow's, the one place the margin is declared). TestCheckJobTestStepsRunUnderTheJobClockWatchdog holds the workflow to them.

It is developer tooling, never part of a release. A step that ends before the deadline exits with the step's own status (128 plus the signal for one a signal ended). A step stopped at the deadline exits 124, as timeout(1) does, with one line on standard error naming the leg, the deadline and the time on the job's clock. Started through go run, as ci.yml starts it, a status other than 0 reaches the runner as go run's own 1, after go run prints the status it got ("exit status 124"). A setting it cannot read, or a command it cannot start, exits 2 before anything runs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL