Skip to content

Async cleanup races on salt-master/minion SIGTERM shutdown #70730

Closed

Description

@dwoz

Symptom 1 — minion-side pending tasks

On every salt-minion SIGTERM the process prints:

Task was destroyed but it is pending!
task: <Task pending name='...' coro=<PubServer._drain_loop() running at salt/transport/tcp.py:1775> wait_for=<Future cancelled>>
Task was destroyed but it is pending!
task: <Task pending name='...' coro=<ZeroMQSocketMonitor.consume() running at salt/transport/zeromq.py:1692> wait_for=<Future cancelled>>

PubServer.close() and ZeroMQSocketMonitor.stop() cancel their
background tasks but, being sync calls, do not drive the event loop
long enough for the cancellation to be delivered — the tasks stay in
the cancelling state and asyncio prints the GC warning on loop
teardown. Cosmetic on a one-shot minion but a real resource leak in
contexts that reuse workers.

Symptom 2 — leader ERROR flood on peer departure

During docker compose down on a cluster, the Raft leader logs
dozens of lines per second:

[ERROR   ] SaltPeer: failed to send cluster/raft/append-entries to salt-master-N

for every peer that is going away. Two causes:

  1. SaltPeer._send logs ConnectionError / StreamClosedError via
    log.exception — ERROR level with a traceback — even though
    peer-unreachable is the normal shutdown signature.
  2. _publish caches a _TCPPubServerPublisher on the pusher and does
    not invalidate it when send() raises. Every subsequent heartbeat
    tick reraises against the same dead stream, never reconnecting.

Fix

  • PubServer.close() routes cancelled drain tasks through
    _drain_cancelled_tasks, which suppresses the pending-destroy
    warning when it cannot drive the loop synchronously.
  • ZeroMQSocketMonitor.stop() sets task._log_destroy_pending = False
    on the cancelled consume task for the same reason.
  • _publish drops the cached async client on send failure.
  • SaltPeer._send demotes expected unreachable-peer exceptions
    (ConnectionError, OSError, StreamClosedError) to DEBUG;
    unexpected exceptions still log at ERROR.

Regression tests in tests/pytests/unit/transport/ and
tests/pytests/unit/cluster/consensus/test_peer.py cover each fix.

Activity

  1. added this to the Argon v3008.7 milestone on Nov 7, 2026
  2. dwoz commented on Nov 10, 2026

    @dwoz
    ContributorAuthor

    Resolved by #70756 (merge commit a40f817 on 3008.x).

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