Repository navigation
Add configurable stall timeout to auto-prune long-stalled workers - #9604
Conversation
|
|
On autoscaling/spot fleets, workers regularly vanish without a graceful retire/land and pile up in the `stalled` state forever, since nothing ever deletes a non-ephemeral worker once stalled. The only existing automatic cleanup, `ephemeral`, deletes a worker ~60-90s after a heartbeat gap and cascades away its entire cache footprint — far too aggressive given the worker->TSA reconnect window can be up to 5 minutes, so a healthy but transiently-disconnected worker gets cache-wiped while still running builds. Add an opt-in `CONCOURSE_WORKER_STALL_TIMEOUT` (default 0 = disabled). When set, the GC worker collector deletes workers that have been `stalled` longer than the timeout. A new `stalled_since` column records when a worker entered the stalled state; heartbeating clears it so a recovered worker resets its grace period and keeps its caches. This gives operators ephemeral-like cleanup without the hair-trigger wipe, because the grace period comfortably exceeds the worst-case reconnect window. Closes concourse#9603 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Tobias Macey <[email protected]>
00c3e04 to
7f2264f
Compare
|
@blarghmatey Can you complete the EasyCLA check please? TY! |
taylorsilva
left a comment
There was a problem hiding this comment.
Solid PR overall. Only minor nits, but I can resolve those after merging. Once your complete the EasyCLA I can merge this. TY!
| -- Backfill existing stalled workers so they are subject to the stall timeout | ||
| -- starting from the moment this migration runs, rather than being immortal due | ||
| -- to a NULL stalled_since. | ||
| UPDATE workers SET stalled_since = now() WHERE state = 'stalled'; |
There was a problem hiding this comment.
Is fine, but not sure how they would be "immortal". Wouldn't the Worker GC component set the stalled_since once it runs? Guess I'll find out as I review this.
There was a problem hiding this comment.
Appreciating how the LLM knew the migration needed to be the "latest" but obviously didn't do a date +%s. Highly doubt it got a unix timestamp with 3 trailing zeros!
Just to make sure it didn't use a timestamp far into the future and messes up future migrations, I checked the current result of date +%s on my machine and got 1781713555, which is after this migrations timestamp. We're all good here!
| "state": string(WorkerStateStalled), | ||
| "expires": nil, | ||
| "stalled_since": sq.Expr("NOW()"), |
There was a problem hiding this comment.
Ah I see, so we set stalled_since when the worker is marked as stalled, not in the GC component. This seems fine then, previous comment in the migration can be ignored.
| VarSourceRecyclePeriod time.Duration `long:"var-source-recycle-period" default:"5m" description:"Period after which to reap var_sources that are not used."` | ||
| } `group:"Garbage Collection" namespace:"gc"` | ||
|
|
||
| WorkerStallTimeout time.Duration `long:"worker-stall-timeout" default:"0" description:"Period after which stalled (unresponsive, non-ephemeral) workers will be automatically pruned along with their cache state. 0 (the default) means stalled workers are never automatically pruned and must be removed manually with 'fly prune-worker'."` |
There was a problem hiding this comment.
| WorkerStallTimeout time.Duration `long:"worker-stall-timeout" default:"0" description:"Period after which stalled (unresponsive, non-ephemeral) workers will be automatically pruned along with their cache state. 0 (the default) means stalled workers are never automatically pruned and must be removed manually with 'fly prune-worker'."` | |
| WorkerStallTimeout time.Duration `long:"worker-stall-timeout" default:"0s" description:"Period after which stalled (unresponsive, non-ephemeral) workers will be automatically pruned along with their cache state. 0s (the default) means stalled workers are never automatically pruned and must be removed manually with 'fly prune-worker'."` |
Because it's type time.Duration we should indicate it accepts a duration format by having the default value be 0s. The other time.Duration flags do this.
There was a problem hiding this comment.
I wonder if the name of the flag here will cause issues when using the quickstart command. That command namespaces all the worker commands from CONCOURSE_ to CONCOURSE_WORKER_. The web commands are not namespaced like this and are left as-is.
Ah easy fix, name it StalledWorkerTimeout!
|
Thanks for the quick review! I'm happy to address the nita if you prefer, otherwise it should be clear to merge as I've signed the CLA |
|
Thanks! I've got a commit with the changes I want, so no worries, I'll fix my nits on main :) |
|
I've update the PR description with the newer flag name |
…leanup from 8.3.0 (#5411) * feat(concourse): adopt stalled-worker and archived-pipeline cleanup from 8.3.0 Prod auto-upgraded to Concourse 8.3.0, which shipped CONCOURSE_STALLED_WORKER_TIMEOUT (the author's own upstream fix, concourse/concourse#9604) and CONCOURSE_DESTROY_ARCHIVED_PIPELINES_AFTER (#9630). Wire both up as a backstop behind the existing concourse-worker-reaper and to reclaim debris left by SetPipelineStep child pipelines that are heavily used across this repo's meta-pipelines. * docs(concourse): clarify archived-pipeline destroy is a global policy Copilot flagged that CONCOURSE_DESTROY_ARCHIVED_PIPELINES_AFTER destroys any archived pipeline, not just set_pipeline orphans -- confirmed against concourse's DestroyArchivedPipelines query (atc/db/pipeline_lifecycle.go), which filters only on archived+age with no distinction by archive reason. Keeping the 30-day window; documenting the global scope so it isn't a surprise for anyone relying on a long-lived manual archive.
Changes proposed by this PR
closes #9603
Adds an opt-in stall timeout so operators can have stalled (unresponsive,
non-ephemeral) workers automatically pruned after a configurable grace period,
without resorting to
ephemeraland its aggressive cache wipe.CONCOURSE_STALLED_WORKER_TIMEOUT/--stalled-worker-timeout(default
0= disabled, preserving today's behavior). When set, the GCworker collector deletes workers that have been
stalledlonger than thetimeout.
stalled_sincecolumn onworkers(migration1781568000_add_stalled_since_to_workers).StallUnresponsiveWorkersstampsit when a worker transitions
running→stalled;HeartbeatWorkerclearsit when a worker reconnects, so a recovered worker resets its grace period and
keeps all of its container/volume/cache rows. The migration backfills existing
stalled workers with
now()so they aren't immortal due to aNULLvalue.DeleteStalledWorkers(timeout)added toWorkerLifecycleand wired intoworkerCollector.Run, analogous toDeleteUnresponsiveEphemeralWorkers. Itonly runs when the timeout is greater than zero.
Why
On EC2 autoscaling/spot fleets, workers regularly disappear without a graceful
retire/landand accumulate installedforever — nothing ever deletes anon-ephemeral worker once stalled. The only existing automatic cleanup,
ephemeral, deletes a worker ~60–90s after a heartbeat gap and cascades awayits entire cache footprint. That's far too aggressive: the worker→TSA reconnect
window is hardcoded to up to 5 minutes (
tsa/client.go), so on an unclean breaka healthy worker can be deleted and cache-wiped while still running builds, only
to reconnect moments later and re-register empty.
A grace-period-based stall timeout (minutes/hours, operator's choice) comfortably
exceeds the worst-case reconnect window: transiently-disconnected workers recover
for free, and only genuinely-dead workers are reaped. This matches the approach
agreed with @taylorsilva in
#9603 (comment)
(build on
atc/gc/worker_collector.go, add a column to track stall age).Notes to reviewer
--worker-stall-timeout.the DB lifecycle (
DeleteStalledWorkersrespects the timeout, leaves runningworkers alone, and a heartbeat clears the stall before the timeout).
CONCOURSE_STALLED_WORKER_TIMEOUTname requested in the issue; happy to move itunder the
gcnamespace (CONCOURSE_GC_WORKER_STALL_TIMEOUT) if maintainersprefer it grouped with the other grace periods.
Release Note
CONCOURSE_STALLED_WORKER_TIMEOUTto automatically prune workers that havebeen stalled longer than the configured duration. Defaults to
0(disabled).