Fix orphaned worker pods: log deletion errors, eliminate TOCTOU race#385
Merged
Fix orphaned worker pods: log deletion errors, eliminate TOCTOU race#385
Conversation
Two bugs caused worker pods to remain running after the janitor marked them retired in the DB: 1. retireWorkerPod silently discarded pod deletion errors with _. If the K8s API delete failed (timeout, network blip), the pod stayed running with no indication in logs. Now logs the error. 2. retireLocalWorker had a TOCTOU race: it checked p.workers[id] then called retireWorkerWithReason which checked again. If the worker was removed between the two checks, retireLocalWorker returned true (thinking it handled it) but the pod was never deleted, and the fallback retireRuntimeWorker was never called. Fix: retireWorkerWithReason now returns bool. retireLocalWorker returns the result directly — no separate existence check. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Worker pods were left running after the janitor marked them
retiredin the DB. Two bugs:1. Silent pod deletion errors
retireWorkerPoddiscarded the K8s API delete error with_. If deletion failed, no log, no retry, pod stays running forever. Now logs the error.2. TOCTOU race in
retireLocalWorkerThe callback checked
p.workers[id], returnedtrue, then calledretireWorkerWithReasonwhich checked again. If the worker was removed between the two checks, the callback reported success but the pod was never deleted, and the fallbackretireRuntimeWorker(which also deletes pods) was never called.Fix:
retireWorkerWithReasonreturnsbool.retireLocalWorkerreturns the result directly with no separate existence check.Observed in prod: 3 worker pods ran for 76+ minutes after hot-idle TTL expiry. DB showed
state=retired, retire_reason=hot_idle_ttl_expiredbut pods were stillRunning.Test plan
go build -tags kubernetes .passes🤖 Generated with Claude Code