Skip to content

MWorker deadlock via nested SyncWrapper in tcp.PublishServer.publish under async fire_event #69986

Open

Description

@dwoz

Summary

Under sustained job-return load on a TCP-transport master, every MWorker
process deadlocks with two threads blocked in threading.Thread.join().
Master CPU drops to idle, find /var/cache/salt/master/jobs -name return.p
throughput falls to near zero, but new TCP connections keep piling up.

Root cause

salt/transport/tcp.py:PublishServer.publish (~line 1943 on 3008.x) wraps
its publisher in SyncWrapper(_TCPPubServerPublisher) via lazy connect().
When publish is invoked from async context — every
MWorker._return -> store_job -> fire_event path runs inside the
request_handler asyncio loop at
salt/transport/zeromq.py:966 — the outer SaltEvent SyncWrapper at
salt/utils/asynchronous.py:214 sees a running loop, spawns a worker
thread, and .join()s it. That worker thread's _TCPPubServerPublisher
SyncWrapper repeats the detection in its own io_loop, spawns yet another
thread, and both threads block on Thread.join() (asynchronous.py:259).
py-spy dump on every MWorker in the wedged state shows the identical
two-thread stack.

Affected branches

3008.x. 3006.x has the same code shape (SyncWrapper + lazy pub_sock) but
uses salt.ext.tornado and @gen.coroutine; a 3006.x patch is a
follow-up (task tracked separately).

Reproduction

Fresh salt-master restart with ~60 already-accepted minions
reconnecting, then tests/monitoring/stress_test_no_api.sh driving
state.apply / state.highstate / test.ping / cp.cache_file at
high concurrency. All 5 MWorkers hit the deadlock within seconds of
job processing starting; py-spy on every worker shows the same two
threads pinned at threading.py:1133 (join) inside nested
SyncWrapper._wrap frames.

Validation of fix

Fix bypasses the outer SyncWrapper when publish is already running
in an async context (asyncio.get_running_loop() succeeds): use the
raw async _TCPPubServerPublisher directly, cached per running loop
in a WeakKeyDictionary and serialised with a per-loop asyncio.Lock
so concurrent fire_event tasks don't interleave length-prefixed
frames on the shared stream. A StreamClosedError on send drops the
cached publisher and rebuilds once inside the lock. With the patch
applied to a 3008.x master under the same stress load, MWorkers stay
responsive and return-file throughput matches minion completion rate
for the full 10 min run.

Related PRs

TBD.

Activity

  1. added this to the Argon v3008.3 milestone on Aug 9, 2026
  2. added
    bug
    on Aug 9, 2026
  3. dwoz commented on Nov 20, 2026

    @dwoz
    ContributorAuthor

    Reopening — #69992 is still in flight.

  4. reopened this on Nov 20, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions