seanmuth commented on PR #68674:
URL: https://github.com/apache/airflow/pull/68674#issuecomment-4836493441

   Independently validated this fix on a live Astro KubernetesExecutor 
deployment (Airflow 3.2.2, `astronomer-kubernetes-executor` 10.18.0 — which 
vendors the cncf executor; its `sync()` / `self.completed` path is 
byte-identical to cncf-kubernetes 10.18.1).
   
   ### Method
   
   `self.completed` is only populated by `_adopt_completed_pods`, which adopts 
`status.phase=Succeeded` pods that aren't yet marked done and belong to a 
**dead** scheduler (the selector excludes the current scheduler and alive 
siblings). A single steady scheduler never adopts its own completing pods, so 
the bug doesn't surface under normal operation — it needs orphaned 
Succeeded-not-done pods.
   
   To trigger it deterministically:
   1. `AIRFLOW__KUBERNETES_EXECUTOR__DELETE_WORKER_PODS=False` so completed 
pods linger as `Succeeded`.
   2. Trigger a DAG with 100 mapped tasks (one worker pod each).
   3. ~45s in, restart the scheduler mid-burst. The restart gap leaves a pile 
of `Succeeded`-not-done pods that the new scheduler adopts into 
`self.completed`.
   
   Measured `Patched pod <key> ... to mark it as done` occurrences per pod 
(`map_index`) in scheduler logs.
   
   ### Results (identical trigger, only the executor code differs)
   
   | | adoption fired | pods | total patch calls | **max per pod** | avg | run 
outcome |
   |---|---|---|---|---|---|---|
   | **Unpatched** (10.18.0) | yes (10 adopt attempts) | 100 | 300 | **21** | 
3.0 | failed |
   | **Patched** (this PR) | yes (24 adopt attempts) | 100 | 124 | **2** | 1.24 
| success |
   
   Without the fix, a single adopted pod was re-patched up to **21 times** and 
the count was still climbing (`self.completed` grows unbounded → scheduler-loop 
starvation). With the fix, despite the patched run actually adopting *more* 
pods (24 vs 10 adoption attempts), re-processing is bounded to ~once per pod 
(max 2, avg 1.24) because `self.completed` is drained after each entry is 
handled. The patched run also recovered through the scheduler restart and 
completed successfully, whereas the unpatched run failed.
   
   LGTM — the `self.completed` dict + drain (`self.completed = still_pending`) 
behaves as intended on a real deployment.
   
   ---
   Drafted-by: Claude Code (Opus 4.8); reviewed by @seanmuth before posting


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to