Repository navigation
Fix PublishChannel fd leak in Minion.eval_master single-master path (#68901) - #69341
Conversation
|
Audit: the prior fd-leak fix on 3006.x (commit 9cd7805, Feb 2026, "Ensure we're not leaking file handles on connect failures") added the try/finally to the multi-master / failover path inside the for master in opts['local_masters'] loop. The single-master sign-in branch (master_type == 'str', the bottom else: at line ~795) was left without the same try/finally — only SaltClientError closes pub_channel; any other exception leaks the socket FD. The existing functional test test_minion_connection_failure_no_fd_leak runs against a single-master config but is heuristic (3 consecutive sample-to-sample increases or +25 vs baseline) and apparently does not consistently catch the leak under its async-teardown tolerances. This PR closes the remaining gap and adds a deterministic unit test that fails on the unfixed tree (close count 0) and passes with the fix. |
When the single-master sign-in branch of MinionBase.eval_master failed, only SaltClientError was handled: AsyncPubChannel.close() was called from inside `except SaltClientError`, but any other exception (e.g. OSError from the transport, asyncio cancellation, or the silent no-raise return from AsyncPubChannel.connect() when its retry sentinel is present) left the just-created channel with its socket still open. The `transport: detect` loop also reassigned `pub_channel` without closing the prior one when authentication had not succeeded. Over thousands of reconnect attempts on flaky networks the minion exhausted its file-descriptor limit and went unresponsive. Mirror the multi-master branch's structure: stage the live channel into ret_pub_channel before raising gen.Return, and use a `try / finally` so the pub_channel is closed on every failure path, not just SaltClientError. In the detect loop close the unauthenticated channel before continuing. Fixes saltstack#68901
What does this PR do?
Closes a file-descriptor leak in the Salt minion. The single-master sign-in
branch of
MinionBase.eval_masteronly ranpub_channel.close()inside anexcept SaltClientErrorclause, so any other failure mode (anOSErrorfrom the transport, asyncio cancellation, or the silent no-raise return
from
AsyncPubChannel.connect()when its-|RETRY|-sentinel is present)left the freshly-created
AsyncPubChannelwith its socket open. Thetransport: detectloop also reassignedpub_channelto the next transportwithout closing the previous unauthenticated one. The fix uses a
try/finally, mirroring the multi-master path, and closes theunauthenticated channel inside the detect loop before continuing.
What issues does this PR fix or reference?
Fixes #68901
Previous Behavior
A minion with an unstable connection to its master accumulated one leaked
socket FD per failed reconnect attempt. Fleets with thousands of minions
hit per-process FD limits (e.g. 10k on Debian/systemd defaults), at which
point the minion goes unresponsive but does not exit, so systemd does not
restart it. Reporter observed daily hits at ~1k minions.
New Behavior
Each failed reconnect attempt closes its
AsyncPubChannelexactly onceregardless of which exception caused the failure. Successful reconnects
hand the live channel off to the caller unchanged.
Merge requirements satisfied?
changelog/68901.fixed.md)tests/pytests/unit/test_minion.py::test_eval_master_single_master_closes_pub_channel_on_failure_68901)Commits signed with GPG?
No - base branch commits are not signed; this PR follows the same convention.