Skip to content

[Bug]: Residual 'Task was destroyed but it is pending' in non-SIGTERM teardown paths (follow-up to #70733) #70748

Closed

Description

@dwoz

Description

Follow-up to #70733 (merged as 7128c04a406), which eliminated the
Task was destroyed but it is pending! asyncio warning on SIGTERM-time
teardown by cancelling + draining PubServer's writer tasks and by
suppressing the GC warning on ZeroMQSocketMonitor.stop()'s
_monitor_task.

The release-notes review for the 3008.x cluster-master stability fixes
observed 8 residual occurrences of the same warning across 2 of 5
minions over a 666 s steady-state window, with #70733 applied
(5× on minion-3, 3× on minion-5). These are not SIGTERM-time.

Root cause

Several long-lived and fire-and-forget minion coroutines are launched
via bare self.io_loop.create_task(coro) without keeping a strong
reference. The Minion._spawn_background helper at
salt/minion.py:4462 documents the exact bug class: under Python 3.10+
asyncio stores Tasks in a module-level WeakSet, so without a
caller-held strong reference CPython's garbage collector can destroy the
Task mid-await, producing the warning and silently dropping the
coroutine's work.

The audit identified 8 vulnerable sites in salt/minion.py — the
MinionManager bootstrap and Minion periodic/dispatch paths, which
are precisely the paths exercised during master-list cycling during
bootstrap. The 1:1 correlation between per-minion bootstrap-time
"Master ip address changed" events (5 and 3 respectively) and the 5× /
3× destroyed-task warnings in the integration-zeta evidence supports
this.

Fix approach

Not a log suppression. Fix properly — keep a strong reference to each
task until it completes, matching the existing _spawn_background
pattern already in use on the same file. No _log_destroy_pending = False added anywhere; every change causes the coroutine to actually
run to completion rather than silencing a GC-collected leak.

Sites

  • MinionManager._spawn_minions → _connect_minion(minion) (line 1963)
  • MinionManager._bind → event_publisher.publisher(...) (line 1843)
  • MinionManager.__init__ → process_manager.run(...) (line 1830)
  • Minion.__init__ → process_manager.run(...) (line 2240)
  • Minion.process_process_queue → _process_process_queue_async() (line 3174)
  • _process_handler → _handle_decoded_payload(data) (line 3322)
  • handle_payload → _handle_decoded_payload(data) (line 4441)
  • Minion state-queue path (line 5405)
  • ping master loop → _fire_master_main(...) (line 5675)
  • SyndicManager._spawn_syndics → connect(...) (line 6444)

Reproduction

Audit note: on the 5-node cluster on the integration branch, brief
cycles (<= 90 s) do not consistently re-hit the warning; the GC trigger
is sporadic. The 666 s integration-zeta window captured it reliably.
Reproduction evidence is already preserved under
agents/reports/integration-zeta/evidence/03-steady-errors.log (in the
dev tree); regression tests assert task-strong-ref invariants directly
rather than depending on a flaky warning repro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions