Skip to content

Add configurable stall timeout to auto-prune long-stalled workers - #9604

Merged
taylorsilva merged 1 commit into
concourse:masterfrom
mitodl:worker-stall-timeout
Jun 18, 2026
Merged

taylorsilva merged 1 commit into
concourse:masterfrom
mitodl:worker-stall-timeout

Conversation

@blarghmatey

@blarghmatey blarghmatey commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

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 ephemeral and its aggressive cache wipe.

  • New config CONCOURSE_STALLED_WORKER_TIMEOUT / --stalled-worker-timeout
    (default 0 = disabled, preserving today's behavior). When set, the GC
    worker collector deletes workers that have been stalled longer than the
    timeout.
  • New stalled_since column on workers (migration
    1781568000_add_stalled_since_to_workers). StallUnresponsiveWorkers stamps
    it when a worker transitions running → stalled; HeartbeatWorker clears
    it 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 a NULL value.
  • DeleteStalledWorkers(timeout) added to WorkerLifecycle and wired into
    workerCollector.Run, analogous to DeleteUnresponsiveEphemeralWorkers. It
    only runs when the timeout is greater than zero.

Why

On EC2 autoscaling/spot fleets, workers regularly disappear without a graceful
retire/land and accumulate in stalled forever — 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. That's far too aggressive: the worker→TSA reconnect
window is hardcoded to up to 5 minutes (tsa/client.go), so on an unclean break
a 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

  • Behavior is unchanged unless the operator opts in by setting a non-zero
    --worker-stall-timeout.
  • New unit tests cover the collector (timeout disabled vs. set, error path) and
    the DB lifecycle (DeleteStalledWorkers respects the timeout, leaves running
    workers alone, and a heartbeat clears the stall before the timeout).
  • The config is exposed as a top-level flag to match the
    CONCOURSE_STALLED_WORKER_TIMEOUT name requested in the issue; happy to move it
    under the gc namespace (CONCOURSE_GC_WORKER_STALL_TIMEOUT) if maintainers
    prefer it grouped with the other grace periods.

Release Note

  • Added CONCOURSE_STALLED_WORKER_TIMEOUT to automatically prune workers that have
    been stalled longer than the configured duration. Defaults to 0 (disabled).

@blarghmatey
blarghmatey requested a review from a team June 17, 2026 00:21
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: blarghmatey / name: Tobias Macey (7f2264f)

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]>
@taylorsilva

Copy link
Copy Markdown
Member

@blarghmatey Can you complete the EasyCLA check please? TY!

@taylorsilva taylorsilva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Solid PR overall. Only minor nits, but I can resolve those after merging. Once your complete the EasyCLA I can merge this. TY!

Comment on lines +3 to +6
-- 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';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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!

Comment on lines +53 to +55
"state": string(WorkerStateStalled),
"expires": nil,
"stalled_since": sq.Expr("NOW()"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread atc/atccmd/command.go
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'."`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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!

@taylorsilva taylorsilva moved this from In Progress to Waiting on Contributor in Pull Requests Jun 17, 2026
@blarghmatey

Copy link
Copy Markdown
Contributor Author

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

@taylorsilva

Copy link
Copy Markdown
Member

Thanks! I've got a commit with the changes I want, so no worries, I'll fix my nits on main :)

@taylorsilva
taylorsilva merged commit f18f106 into concourse:master Jun 18, 2026
11 checks passed
@github-project-automation github-project-automation Bot moved this from Waiting on Contributor to Done in Pull Requests Jun 18, 2026
@taylorsilva

Copy link
Copy Markdown
Member

I've update the PR description with the newer flag name CONCOURSE_STALLED_WORKER_TIMEOUT/--stalled-worker-timeout.

@taylorsilva taylorsilva added this to the v8.3.0 milestone Jun 18, 2026
blarghmatey added a commit to mitodl/ol-infrastructure that referenced this pull request Aug 14, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Add configurable stall timeout to auto-prune long-stalled workers (ephemeral is too aggressive for cache-heavy spot fleets)

2 participants