bug: node waiting on multiple template-level locks leaks wait-queue entries of all but one lock when it errors, blocking the lock forever

Author: GufderaldCreated Sep 18, 2026Updated Sep 22, 2026

Pre-requisites

  • I have double-checked my configuration
  • I can confirm the issue exists when I tested with :latest
  • I'd like to contribute the fix myself

What happened/what you expected to happen?

A template declares more than one lock (a semaphore and a mutex). One of its nodes is enqueued on all of them, waits, and then goes to Error before it ever acquires the locks. The node's entry stays in the wait queue of every lock except the one recorded in node.SynchronizationStatus.Waiting. This remains true after the Workflow completes.

Any later node, including one in a different Workflow, that requests the leaked lock then waits forever. The lock is free, so the message reads Lock status: 1/1, and no holder is visible anywhere. The controller logs "isn't at the front" every reconcile. Only a workflow-controller restart clears the queue, because it rebuilds the queue from live Workflows.

Expected: when a Workflow completes, every lock the node was enqueued on drops its wait-queue entries.

Root cause (from reading v4.1.3; the code is unchanged in v4.1.4 and main)

  1. Manager.TryAcquire → prepAcquire (workflow/sync/sync_manager.go) calls lock.addToQueue(holderKey, ...) for every lock in the template's synchronization.
  2. If any lock is not acquirable, executeTemplate calls markNodeWaitingForLock(node, failedLockName, ...). NodeSynchronizationStatus.Waiting is a single string, so it records only the first lock that failed.
  3. Manager.ReleaseAll cleans node-level waiters only through that field:
    go
    for _, node := range wf.Status.Nodes {
        if node.SynchronizationStatus != nil && node.SynchronizationStatus.Waiting != "" {
            lock, ok := sm.syncLockMap[node.SynchronizationStatus.Waiting]
            ...
            lock.removeFromQueue(ctx, getHolderKey(wf, node.ID))
    The node's holder key therefore stays in the queues of the other locks. The workflow-level Mutex.Waiting / Semaphore.Waiting loops above it only remove the workflow-level key (getHolderKey(wf, "")), so they do not help.

Manager.Release(wf, nodeID, syncRef) does iterate over all of the template's locks and calls removeFromQueue for each. It is only reached on the normal node-completion paths, not on the error path described below.

In our case the node errored in executeTemplate because of the displayName validation. That check only runs when node != nil. On the first reconcile the node does not exist yet, so the check is skipped: TryAcquire enqueues the node on both locks and the node is created Pending. On the next reconcile the node exists, the check fails, and initializeNodeOrMarkError returns before any Release call. Any error between enqueueing and acquiring should leak the same way. The display-name check is just the one we hit.

Timeline from our controller logs (v4.1.3, in-memory locks, no sync DB)

Template job has a mutex city-<param> and a ConfigMap semaphore writers (limit 2). Workflow wf-A is submitted via workflowTemplateRef from a CronWorkflow.

09:22:03.527 TryAcquire syncLockName={ns resourceName:sync key:writers kind:ConfigMap}
09:22:03.527 TryAcquire syncLockName={ns resourceName:city-X key: kind:Mutex}
09:22:03.530 "node initialized" node=wf-A-1315832738 phase=Pending
09:22:03.530 "Could not acquire lock" lockName=ns/ConfigMap/sync/writers
09:22:13.585 "node phase changed" node=wf-A-1315832738 fromPhase=Pending toPhase=Error
             message="displayName must match the regex ^[a-zA-Z0-9][a-zA-Z0-9-.]{0,61}[a-zA-Z0-9]$"
09:22:13.595 "Released all acquired locks" key=wf-A
             (releases only the Holding entries of other nodes; nothing logged for the city-X queue)

The mutex ns/Mutex/city-X has no acquired event anywhere in the logs. An hour later, workflow wf-B requests the same mutex, and its node stays Pending for as long as we have watched it:

bash
10:23:55.203 TryAcquire ... resourceName:city-X kind:Mutex
10:23:55.203 "isn't at the front" lockType=mutex name=ns/Mutex/city-X holderKey=ns/wf-B/wf-B-3084600097
... repeated every reconcile, 68 times over ~20 minutes ...
node message: "Waiting for ns/Mutex/city-X lock. Lock status: 1/1"

wf-B.status.synchronization.mutex is {}. Nothing in any Workflow's status shows a holder or an earlier waiter.

Paste a small workflow that reproduces the issue.

We derived this from the production timeline and the code above; we have not run it as a standalone repro yet.

yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: leak-repro-sync
data:
  writers: "1"
---
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: leak-repro
spec:
  entrypoint: main
  templates:
    - name: main
      dag:
        tasks:
          - name: holder            # takes the only semaphore slot
            template: job
            arguments: {parameters: [{name: label, value: "ok"}, {name: sleep, value: "60"}]}
          - name: victim            # waits on the semaphore, is enqueued on the mutex too,
            template: job           # then errors on displayName on the next reconcile
            arguments: {parameters: [{name: label, value: "has space"}, {name: sleep, value: "1"}]}
    - name: job
      inputs:
        parameters: [{name: label}, {name: sleep}]
      annotations:
        workflows.argoproj.io/display-name: "job-{{inputs.parameters.label}}"
      synchronization:
        semaphores:
          - configMapKeyRef: {name: leak-repro-sync, key: writers}
        mutexes:
          - name: leak-repro-{{inputs.parameters.label}}
      container:
        image: busybox
        command: [sleep, "{{inputs.parameters.sleep}}"]
  1. Submit a Workflow from leak-repro and wait for it to finish (Error, because of victim).
  2. Submit a Workflow whose template takes only the mutex leak-repro-has space. Its node stays Pending with Lock status: 1/1 until the controller restarts.

Suggested fix

  • In ReleaseAll, remove each node's holder key from every lock it could be queued on, not only SynchronizationStatus.Waiting. One way: resolve the node's template synchronization as Release does. Another: sweep syncLockMap for holder keys prefixed with <ns>/<wf>/.
  • Alternatively or additionally, call syncManager.Release(...) on the error returns in executeTemplate that happen after the node may already be enqueued.
  • Maybe also run the displayName validation before TryAcquire on the first reconcile (node == nil), so that a node never enters a lock queue for a template that is bound to fail.

Workaround

Restart the workflow-controller.

Related

  • #16924: another way a wait-queue entry can leak (the pending-shutdown path uses execWf).
  • #14080: the misleading Lock status: N/N message when the waiter is not at the front of the queue.

Version(s)

v4.1.3 (controller image quay.io/argoproj/workflow-controller:v4.1.3). We compared workflow/sync/sync_manager.go, workflow/sync/semaphore.go and the relevant parts of workflow/controller/operator.go: they are unchanged in v4.1.4 and on main as of 2026-09-18.

Logs from the workflow controller

See the timeline above; names are anonymized.