You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pipeline: a failed stage's instance is never terminated, and the TTL reaper cannot see it (no spawn:managed tag) #912
Found while fixing #906. Cost safety. Found by reading the code; not reproduced against AWS (no instances launched).
When a pipeline stage's command fails, its instance is never terminated and nothing else will ever reclaim it:
The instance doesn't terminate itself on failure. In the user data from lambda/pipeline-orchestrator/main.gogeneratePipelineUserData, the failure branch (timeout %s bash -c "$STAGE_CMD" || { ...; exit $EXIT_CODE }) writes the FAILED marker and exits. Only the success path reaches aws ec2 terminate-instances. The stage timeout firing takes the same branch.
The orchestrator never notices the failure.checkStageCompletion looks for the COMPLETE marker only; nothing reads FAILED. Its fallback, "all instances terminated", reads InstanceInfo.State, which is set once at launch ("pending") and never refreshed (allInstancesRunning is a 1-minute heuristic with a TODO). The stage stays running, allStagesComplete never holds, and the Lambda re-invokes itself every ~13 minutes indefinitely. StageStatusFailed is set only when the launch call itself fails.
The TTL reaper can't see it.launchStageInstance tags only spawn:pipeline-id, stage-id, stage-index, instance-index and Name: no spawn:managed, no spawn:ttl-deadline, no launch time. The reaper lists only spawn:managed=true instances (lambda/ttl-reaper/main.goscanRegion), and its terminate grants are conditioned on that tag (see the comment on the pipeline security group, which got LifecycleTags for exactly this reason). The instances also get no TTL and no InstanceInitiatedShutdownBehavior.
Also on the success path, self-termination uses ec2-metadata --instance-id, which exists on Amazon Linux but not on Ubuntu/Debian AMIs. On those, the terminate step gets an empty id and fails, so even a successful stage instance runs on, and is only cleaned up if the user cancels the pipeline.
Result: a stage whose command exits non-zero leaves an instance running, and billing, until someone cancels the pipeline by hand. The reaper is no backstop.
Suggested:
Tag stage instances with spawn.LifecycleTags plus a TTL deadline taken from the stage timeout, so the reaper covers them.
Terminate on the failure path too, or shutdown -h with InstanceInitiatedShutdownBehavior=terminate.
Have checkStageCompletion read FAILED and mark the stage failed.
Get the instance id from IMDS instead of ec2-metadata.
Activity
Terminate failed pipeline stages and make them reapable (#912)
Terminate failed pipeline stages and make them reapable (#912) (#931)
Run the spored stage runner in pipeline stages, so data_input/data_ou…
Run the spored stage runner in pipeline stages, so data_input/data_ou…
Run the spored stage runner in pipeline stages, so data_input/data_ou…