Multiple returns from minions when multi-master is used.
Greetings,
I have looked at a number of issues like this on here and other sites and have not seen a true solution to the issue, instead most seem to focus on the different symptoms and not the under lying cause... Unfortunately, that means none of the existing solutions has really fixed the problem. We first saw this issue in Salt 2014.1.10 and continue to see it in 2015.8.x
So the basic problem: When you have multi-master configured, per the Salt documentation, you can get into a situation where each Salt command generates multiple returns for random minions. A simple example of this;
jwells@saltsyndic:~$ salt \* test.ping
random-minion-001: true
random-minion-005: true
random-minion-005: true
random-minion-003: true
random-minion-001: true
random-minion-002: true
When we run the same command from out Salt M-O-M (Master-Of-Masters) cluster this effect is consistent for the Salt Syndic / Master boxes and more random for the minions.
Our original structure was;
- 1 x Salt M-O-M (Running Ubuntu, Salt Master, Salt Minion) -- CNAME saltmaster
- 2 x Salt Syndic / Master (Running Ubuntu, Salt Master, Salt Minion, and Salt Minion) -- CNAME salt
- ~750 Salt Minion (Running Ubuntu and Salt Minion)
The Salt Minion nodes were configured to connect to both of the Salt Syndic / Master nodes using a single DNS CNAME and when that didn't work we converted to a VIP (Same result and fail-over was unstable);
master: salt
We found a discussion somewhere that indicated that the minion config needed to use two different names (Same result, though it failed over gracefully);
master:
salt-001
salt-002
In another discussion we saw that it was caused by multiple instances of Salt Syndic running, so we created a script to periodically kill all instances and restart it. Same result.
Another discussion stated that it was because we didn't have master_id set, or because we had order_masters, or because we didn't have it set... At that point, we went to a single Salt M-O-M, and a single Salt Syndic / Master at each site.
We recently started the process of upgrading to Salt 2015.8.x and, due to other issues, we decided to go back to the multi-master configuration. And see this issue is still present. :(
Our setup;
- 2 x Salt M-O-M (Running Ubuntu, Salt Master, Salt Minion, and Gluster to share /etc/salt/pki/master)
- 2 x Salt Syndic / Master (Running Ubuntu, Salt Master, Salt Minion, Salt Syndic, and Gluster to share /etc/salt/pki/master)
- N x Salt Minion (Running Ubuntu, Salt Minion)
The Salt M-O-M, are both running the same versions / configurations as verified by Salt and md5sum. The relevant portions of the Salt Master configurations are (minion_id == saltmom-001 or saltmom-002 respectively);
order_masters: true
master_id: <minion_id value>
Just for completeness, here is the relevant portion of the Salt Minion configuration;
master:
- saltmom-001
- saltmom-002
The Salt Syndic / Master are near identical to the Salt M-O-M configuration, but they have an extra entry for Syndic (minion_id == salt-001 or salt-002 respectively);
order_masters: true
master_id: <minion_id value>
syndic_master:
- saltmom-001
- saltmom-002
And the relevant portion of the Salt Minion configuration;
master:
- salt-001
- salt-002
With just this configuration in place, if I do a 'salt * test.ping', from either of the Salt M-O-M boxes, I would expect to get back something like the following;
jwells@saltmom-001:~$ salt \* test.ping --output=yaml
saltmom-001: true
saltmom-002: true
salt-001: true
salt-002: true
Instead what I get back is something like;
jwells@saltmom-001:~$ salt \* test.ping --output=yaml
saltmom-001: true
salt-001: true
saltmom-002: true
salt-001: true
salt-002: true
salt-002: true
And Salt Master logs on the Salt M-O-M show something like;
2015-11-11 11:25:12,535 [salt.utils.job ][INFO ][12496] Got return from salt-002 for job 20151111112511812434
2015-11-11 11:25:12,577 [salt.utils.job ][INFO ][12513] Got return from salt-002 for job 20151111112511812434
2015-11-11 11:25:12,579 [salt.loaded.int.returner.local_cache][ERROR ][12513] An extra return was detected from minion salt-002, please verify the minion, this could be a replay attack
Now, if we add minions to the Salt Syndic / Master boxes, we will get the same duplicate responses on the Salt M-O-M, but not if we call it from the Salt Syndic / Master boxes. For completeness, their relevant configuration is;
master:
- salt-001
- salt-002
When we look at the Salt Master logs on the Salt Syndic / Master, we see the following;
2015-11-11 11:25:12,535 [salt.minion ][INFO ][27256] Returning information for job: 20151111112511812434
2015-11-11 11:25:12,571 [salt.minion ][INFO ][27256] Returning information for job: 20151111112511812434
So the Salt Syndic is returning the correct information, but then if we look at the other Salt Syndic / Master's syndic log file we find the same jobs being returned. So the Salt M-O-M get's two copies of the same return, marks one of them as "An extra return" and will display it in the output.
Finally, I should point out that this is not completely consistent. We do get the occasional entry like this;
jwells@saltmom-001:~$ salt \* test.ping --output=yaml
saltmom-001: true
salt-001: Minion did not return. [Not connected]
saltmom-002: true
salt-001: true
salt-002: true
salt-002: true
All of the nodes in the new environment have the same versions of Ubuntu packages, Python, and Salt;
jwells@saltmom:~$ sudo salt-run --versions-report
Salt Version:
Salt: 2015.8.0
Dependency Versions:
Jinja2: 2.7.2
M2Crypto: Not Installed
Mako: 0.9.1
PyYAML: 3.11
PyZMQ: 14.4.0
Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
RAET: Not Installed
Tornado: 4.2.1
ZMQ: 4.0.4
cffi: Not Installed
cherrypy: Not Installed
dateutil: 1.5
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
libnacl: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.3.0
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pygit2: Not Installed
python-gnupg: Not Installed
smmap: Not Installed
timelib: Not Installed
System Versions:
dist: Ubuntu 14.04 trusty
machine: x86_64
release: 3.13.0-66-generic
system: Ubuntu 14.04 trusty
@nikatjef thanks for the report. Does this behavior occur every time you run a command against your minions?
There was some work done on multi master to fix the following issue: #21744 and the fix is located here: #28302 . Although this issue is different from your problem with multi-master I did some testing to make sure this new fix was working and in my testing i did not see multiple returns from minions, although I did not do any testing with syndics. This new fix will be included in 2015.8.2 which should be coming out soon. I would be curious if this new fix would fix your issue. Would you be willing to check to see if this fixes this behavior?
The behavior as a whole does appear to happen every time for the Salt Syndic / Master boxes.
The Salt Minions (reporting to those Salt Syndic / Master boxes) also appear to behave this way, but not quite as consistently. I suspect that the lack of consistency is related to a separate issue (https://github.com/saltstack/salt/issues/25028).
I will need to upgrade to 2015.8.1 before I can test it as it looks like there are a couple of constructs missing from the 2015.8.0 version of salt/transport/zeromq.py
@nikatjef thanks for the additional information. I did find this issue: #21601 where a user was receiving multiple returns in a syndic scenario, and resolved it because he had multiple syndic processes running. He did not have a multi-master setup so I believer your setup is a separate issue. But in this issue basepi explained the following:
"This is very odd. The only time I would expect to see behavior like this is in a multi-master syndic setup. If minions are connected to multiple masters, and those masters are all connected to a master of masters, then the minion will get the job multiple times (once from each master). Are you using multi-master at all?" I believe this explains your setup correctly, please correct me if i'm wrong.
@basepi do you believe this above issue is expected behavior? He is using a mult-master syndic setup.
Yes. The issue is that the minion doesn't keep track of jids it has already executed. It just executes a job every time it receives a job. So when you pub a job from the master of masters through two syndic masters, with a minion underneath connected to both, the minion receives to jobs, and so it runs and returns two jobs.
This is a fairly common use case, so we need to at some point add this filtering mechanism, I think. I'm pretty sure we already have an issue open for it somewhere, but I can't find it off the top of my head.
Thanks for the clarification @basepi . I am going to re-label this as a feature-request
Just a quick update on this.
While working on an unrelated issue, I used the queue option to serialize a couple of state calls and found out that the minion does indeed execute process the same jids multiple times, so the results showing multiple returns for a single minion are "correct". The M-O-M is getting multiple returns because the minion is processing the request once for each syndic / master.
I want to explore doing this with an in memory jid cache on the minion
How would I enable that please? I still have that environment and it continues to be something I deal with randomly... Like when I forget this and write my states or python scripts without protections.
EDIT: Accidentally closed this, re-opening.
ok, so when the minion gets the pub message from the master it decides if it should execute it, so we should have a set that stores all the jids that we have executed, and then we compare the jid from the master to the set of jids. When the jid set is over say 100-500 we clean it down (which makes me think it should be a list)
I don't know about anyone else, but even 100 jids seems excessive to me. Prior to moving to 2015.8, it would have been about 4 days for us to have gotten to 100 jids. With 2015.8, we got the new scheduler which generates far more jids, but I think it would still be almost a full day to reach 100 jids.
My personal recommendation would be a small dict containing the jid and the time it completed the return... Then roll jids off after at a configurable delay after completion of the return... Say 60 minutes by default.
@nikatjef - we ran into the same issues. Our solution was instead to connect the minions to the syndics in failover mode, rather than multi-master.
In failover mode, the minion is only ever connected to 1 syndic at a time. If that syndic was to fail, it fails over to the second syndic.
There are still some issues around this - due to the long-lived nature of salt minion connections, but there have been some improvements with this, and works for the scenario if you're just trying to provide some type of HA.
Thanks for the feedback, and while I agree that most deployments will not use 100 jids per minion within a small timeframe, the goal remains to create a software that is resilient to a wide range of situations, and 100 jids in a list or set still represent a very small footprint and can be easily compared against. It should also be made configurable of course :)
@thatch45 - Fair enough. :)
@sjmh - We ended up going that route during our build phase, just to get things working. Unfortunately, that model will not work for us in the long run.
Our intent is to have a single pair of M-O-M that can be managed from our corporate headquarters, and then a pair of syndic / masters at each data center / corporate office. The It / Ops team at each site will have the ability to manage their site via the syndic / masters. A single state or query could be run against the M-O-M to affect our entire network, or a single state or query could be run at a single site to affect only the minions at that site.
Your model starts to break down at the site level where you need to execute the same state or query multiple times, once for each syndic / master, to affect all of the minions at the site.
Yeah - we don't allow for executions at the syndics level - we just do everything from the master and target sites by grains.
You could get around that issue by writing a wrapper to send the job to both syndics.
ZD-805
Would like to get this in for Carbon
Got the same issues. MoM gets multiple responses from minion.
Setup is simple:
- MoM
- Syndic node
- Minion
when running test.ping:
[salt]# salt \* test.ping --output=yaml
sm-is01: true
web: true
sm-is01: true
web: true
vm: true
vm: true
Logs are showing same error:
2017-11-09 15:56:56,200 [salt.loaded.int.returner.local_cache][ERROR ][54578] An extra return was detected from minion web, please verify the minion, this could be a replay attack
2017-11-09 15:56:57,697 [salt.loaded.int.returner.local_cache][ERROR ][54577] An extra return was detected from minion vm, please verify the minion, this could be a replay attack```
@0x6c can you please open a new issue since this issue is closed and fixed, with additional details such as version this is affecting you in and configuration setup