Skip to content

Rebase master - #2

Merged
ggiesen merged 1331 commits into
ggiesen:masterfrom
saltstack:master
Feb 13, 2021
Merged

ggiesen merged 1331 commits into
ggiesen:masterfrom
saltstack:master

Conversation

@ggiesen

@ggiesen ggiesen commented Feb 13, 2021

Copy link
Copy Markdown
Owner

Rebase master

asomers and others added 30 commits February 3, 2021 10:37
The value is "VMware Photon" only on Photon OS 1.0, where there is no
python3 package available, so I think it's fair to ignore that.
meaksh and others added 26 commits February 11, 2021 06:21
openSUSE 15.3 and SLES 15 SP3 have removed the compatibility symlink for
/usr/share/grub2/x86_64-xen/grub.xen to
/usr/lib/grub2/x86_64-xen/grub.xen. virt._gen_xml() need to check which
is present and put in Xen PV VMs XML definition.
@ggiesen
ggiesen merged commit cf208e0 into ggiesen:master Feb 13, 2021
ggiesen pushed a commit that referenced this pull request Jun 8, 2026
Closes three gaps identified in the Raft correctness audit.

Dynamic join — joiner starts as learner (priority #2 & saltstack#6)
-----------------------------------------------------------
A master that joins via discover_peers starts _publish_daemon before the
join handshake completes, so cluster_peers is empty and RaftService is not
started.  Once join-reply arrives the MasterPubServerChannel now calls
_start_raft_as_learner(), which:
  - builds pushers to every peer received in join-reply (fixes gap saltstack#6:
    dispatcher had no pushers to reply to the leader)
  - starts RaftService with voting=False (fixes gap #2: joiner was starting
    as a voter, risking split-brain before the leader promoted it)

salt/channel/server.py
- _start_raft_as_learner(known_peers): new helper started from the
  join-reply handler; builds peer pushers and calls
  RaftService(voting=False).
- join-reply handler: calls _start_raft_as_learner after event.set().

salt/cluster/consensus/service.py
- RaftService(voting=True): new optional parameter passed to Node so the
  node starts in learner mode when the master joined dynamically.

Founding CONFIG entry (priority saltstack#5)
-------------------------------------
The first elected leader of a fresh cluster now writes a CONFIG entry
recording the founding voter set before any application entries.  This
makes cluster membership durably verifiable from the log alone.

salt/cluster/consensus/service.py
- _maybe_commit_founding_config(): proposes {voters, learners} CONFIG entry
  when the leader's log is empty; no-ops if the log already has content.
- _heartbeat_tick: calls _maybe_commit_founding_config() on every tick
  while leader (the guard makes it idempotent).

Tests
-----
tests/pytests/functional/cluster/consensus/test_raft_service.py
- TestFoundingConfig: leader writes CONFIG entry on empty log; no-ops if
  log is non-empty.
- TestDynamicJoinerAsLearner: RaftService(voting=False) produces a
  non-voting node; learner-mode service does not start elections.
ggiesen pushed a commit that referenced this pull request Jun 8, 2026
This commit fixes catastrophic FD exhaustion in Salt minions running
queued state jobs. The issue manifested as "Too many open files" errors
after ~15 queued jobs.

Root causes and fixes:

1. Unawaited coroutine (salt/utils/event.py:785)
   - Changed self.pusher.publish(msg) to await self.pusher.publish(msg)

2. Unclosed event loops in job threads (salt/minion.py)
   - Added loop.close() in finally blocks of _thread_return() and _thread_multi_return()

3. SyncWrapper __getattr__ preventing cleanup (salt/utils/event.py)
   - Explicitly call SyncWrapper.close() instead of relying on __getattr__

4. Missing task cancellation (salt/utils/asynchronous.py)
   - Cancel pending tasks before closing event loop
   - Shutdown async generators with shutdown_asyncgens()
   - Shutdown executor with shutdown_default_executor()

5. IOLoop auto-creation (salt/utils/asynchronous.py)
   - Changed IOLoop.current() to IOLoop.current(instance=False)

6. Nested SyncWrapper in TCP transport (salt/transport/tcp.py)
   - Explicitly close pub_sock SyncWrapper in PublishServer.close()

7. Unclosed TCP client (salt/transport/tcp.py)
   - Added _tcp_client.close() in PublishClient.close()

8. Async generator/executor shutdown (salt/utils/asynchronous.py)
   - Call shutdown_asyncgens() and shutdown_default_executor() before loop close

Impact:
- Before: 237 FDs leaked per 15 queued jobs → OSError after ~40 jobs
- After: 0 FDs leaked (multiprocessing), minimal leaks (threading)

Tests added:
- tests/pytests/scenarios/queue/test_queue_fd_leak.py
  Comprehensive regression test for the reported bug

- tests/pytests/scenarios/regression/test_fd_leak_fire_event_async.py
  Regression test for fix #1 (unawaited coroutine)

- tests/pytests/scenarios/regression/test_fd_leak_job_thread_loop.py
  Regression test for fix #2 (job thread event loop close)

- tests/pytests/scenarios/regression/test_fd_leak_syncwrapper_close.py
  Regression test for fix #3 (SyncWrapper explicit close)

- tests/pytests/scenarios/regression/test_fd_leak_task_cancellation.py
  Regression test for fix #4 (task cancellation and cleanup)

- tests/pytests/scenarios/regression/test_fd_leak_ioloop_instance.py
  Regression test for fix saltstack#5 (IOLoop.current(instance=False))

- tests/pytests/scenarios/regression/test_fd_leak_tcp_nested_syncwrapper.py
  Regression test for fix saltstack#6 (nested SyncWrapper in TCP)

- tests/pytests/scenarios/regression/test_fd_leak_tcp_client_close.py
  Regression test for fix saltstack#7 (TCP client close)

- tests/pytests/scenarios/regression/test_fd_leak_asyncgens_executor.py
  Regression test for fix saltstack#8 (async generator and executor shutdown)

All regression tests:
- Use real Salt master/minion infrastructure (not mocks)
- Measure actual FD counts with psutil
- Exercise specific code paths that were leaking
- Assert FD leaks are minimal (≤ threshold)
ggiesen pushed a commit that referenced this pull request Aug 15, 2026
Real CI on PR saltstack#69812 surfaced that redact_state_ret_secrets()'s
_collect_secret_literals() has no cycle-detection guard, unlike its
siblings serial()/mask_output()/expose() in the same file. In the
state.orchestrate/runner path, self.opts.get("pillar") is an
OptsDict/ListProxy with a self-referential __iter__, so the recursive
walker crashes with RecursionError - state.orchestrate fails outright
in ~15 tests, not just degraded output.

Separately, and even setting the crash aside, the literal-substring
scan has no way to distinguish an actual secret from an ordinary
pillar value used as a template parameter. Confirmed at real scale:
the words "branch" and "master" - core Salt/git vocabulary - are
present somewhere in the CI harness's minion pillar and got redacted
out of unrelated assertions, breaking tests/integration/states/test_git.py
(6 tests, every OS in the matrix) plus several salt-ssh suites. ~30
distinct upstream tests failed across ~9 platforms.

Removes redact_state_ret_secrets()/redact_known_secrets()/
_collect_secret_literals() and the call site in salt/state.py. Reverts
the three test files that were patched only to accommodate this
mechanism's fallout (test_state_test.py, test_salt_call.py's
test_42116_cli_pillar_override, test_file.py's test_state_skip_req)
back to their original assertions. Keeps the unrelated unmask=True
fixes (a real, independent pre-existing bug) and gap #2 (name masking
under no_log), neither of which caused any CI failures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.