PreDelete/PostDelete hook deleted before it executes
Checklist:
- I've searched in the docs and FAQ for my answer: https://bit.ly/argocd-faq.
- I've included steps to reproduce the bug.
- I've pasted the output of
argocd version.
Describe the bug
AlreadyExists race in executeHooks marks the hook phase complete against a stale cluster cache.
When an Application with a PreDelete hook is deleted while the controller processes multiple finalization passes in quick succession (normal during deletion, which generates a burst of app updates), the hook resource can be created by one pass and then the next pass — running before the controller's cluster cache has observed the new resource — declares the entire PreDelete phase complete. The controller then removes the pre-delete finalizer and starts cascade deletion, which deletes the still-starting hook resource itself (it carries app-instance tracking). Net effect: the hook is created and killed within seconds, never executes, and deletion proceeds as if it had run. PostDelete hooks share executeHooks, so they are equally affected.
runningHooksis built exclusively fromliveObjs— a cluster-cache snapshot: https://github.com/argoproj/argo-cd/blob/v3.5.0/controller/hook.go#L125-L130- Pass A: cache has no hook → hook is in
expectedHook→CreateResourcesucceeds → returns(false, nil)to wait. ✔ - Pass B, sub-second later: cache still has no hook → create attempt →
409 AlreadyExists→ warn andcontinue, discarding the fact that the hook was just proven to exist: https://github.com/argoproj/argo-cd/blob/v3.5.0/controller/hook.go#L161-L165 createdCnt == 0, so the "created hooks, wait" early-return is bypassed: https://github.com/argoproj/argo-cd/blob/v3.5.0/controller/hook.go#L171-L174- The health check iterates the empty
runningHooksmap — zero progressing, zero failed: https://github.com/argoproj/argo-cd/blob/v3.5.0/controller/hook.go#L187-L235 - Fall-through →
return true, nil— phase declared complete: https://github.com/argoproj/argo-cd/blob/v3.5.0/controller/hook.go#L235 - Caller removes the pre-delete finalizer and proceeds to cascade deletion, which deletes the hook created in step 2 (it carries app-instance tracking via
SetAppInstance): https://github.com/argoproj/argo-cd/blob/v3.5.0/controller/appcontroller.go#L1288-L1298 - Same pattern for PostDelete: https://github.com/argoproj/argo-cd/blob/v3.5.0/controller/appcontroller.go#L1370
The observed timeline with Argo CD v3.4.5 single controller replica, where the hook is a Job that terminates DB connections before a Crossplane-managed DROP DATABASE is issued:
13:40:33 Application deletionTimestamp set
13:40:33 Job <app>-db-conn-cleanup created; pod scheduled (pass A)
13:40:33 level=warning msg="Hook resource {batch Job staging <app>-db-conn-cleanup} already exists, skipping" (pass B)
13:40:38 Pod: Pulled, Created, Started
13:40:38 Pod: Killing <- cascade deletion removed the hook Job the same second its container startedThe hook's container never executed (no logs, no side effects).
With controller loglevel warn, the only visible trace is the single warning line — Creating %s hook resource and Created %d hooks are info-level — making the failure effectively silent.
To Reproduce
An Application whose manifests include a Job annotated argocd.argoproj.io/hook: PreDelete (e.g. sleep 30); delete the app under conditions producing back-to-back finalization passes — e.g. deletion via an ApplicationSet/parent-app cascade, or kubectl annotate touches on the Application right after kubectl delete. Intermittent by nature — it races the informer cache update. Fingerprint: the already exists, skipping warning plus the hook pod killed within seconds of starting.
Expected behavior
The PreDelete hook runs to completion (or failure) before the finalizer is removed and cascade deletion begins.
A proposed fix by Claude Fable 5: in the AlreadyExists branch, treat the hook as running instead of skipping it — simplest: return false, nil (requeue; the informer surfaces the resource on a later pass, after which normal health evaluation takes over). Alternatively, on AlreadyExists, GET the live object and include it in runningHooks before the health check. Either way, phase completion must not be decided from a cache snapshot that a create attempt has just proven stale.
Version
argocd: v3.2.5+c56f440
BuildDate: 2026-01-14T19:59:54Z
GitCommit: c56f4400f22c7e9fe9c5c12b85576b74369fb6b8
GitTreeState: clean
GoVersion: go1.25.5
Compiler: gc
Platform: darwin/arm64
{"level":"warning","msg":"Failed to invoke grpc call. Use flag --grpc-web in grpc calls. To avoid this warning message, use flag --grpc-web.","time":"2026-08-07T19:01:02+03:00"}
argocd-server: v3.4.5
BuildDate: 2026-07-09T16:15:22Z
GitCommit: 564b94973b284b8de98da7cee6eeade2cb941e46
GitTreeState: clean
GitTag: v3.4.5
GoVersion: go1.26.0
Compiler: gc
Platform: linux/amd64
Kustomize Version: v5.8.1 2026-02-09T16:15:27Z
Helm Version: v3.19.4+g7cfb6e4
Kubectl Version: v0.34.0
Jsonnet Version: v0.21.0Source: argoproj/argo-cd