salt icon indicating copy to clipboard operation
salt copied to clipboard

salt minions 'sleep' after some idle time?

Open lloesche opened this issue 12 years ago • 46 comments

I have 22 salt minions connected to a master. The behaviour I'm observing is this:

When I'm actively using salt all minions react to e.g. test.ping no problem. However when they've been idle for a while e.g. overnight, it takes a couple of salt calls to get them all to react. It's as if they are being woken up?

I couldn't find anything in the documentation about this behaviour and the minion log is empty without any kind of messages whatsoever.

The following commands have been executed without any pause in between them:

[root@kvm2 ~]# salt '*' test.ping
tcub1404n42:
    True
tcub1404n35:
    True
tcub1404n23:
    True
tcub1404n25:
    True
tcub1404n40:
    True
[root@kvm2 ~]# salt '*' test.ping
tcub1404n23:
    True
tcub1404n33:
    True
tcub1404n40:
    True
tcub1404n25:
    True
tcub1404n24:
    True
tcub1404n35:
    True
tcub1404n30:
    True
tcub1404n34:
    True
tcub1404n41:
    True
tcub1404n42:
    True
tcub1404n38:
    True
tcub1404n36:
    True
tcub1404n28:
    True
tcub1404n31:
    True
[root@kvm2 salt]# salt '*' test.ping
tcub1404n42:
    True
tcub1404n34:
    True
kvm2.hv.de1:
    True
tcub1404n27:
    True
tcub1404n38:
    True
tcub1404n31:
    True
tcub1404n39:
    True
tcub1404n33:
    True
tcub1404n35:
    True
tcub1404n24:
    True
tcub1404n23:
    True
tcub1404n22:
    True
tcub1404n25:
    True
tcub1404n26:
    True
tcub1404n29:
    True
tcub1404n37:
    True
tcub1404n40:
    True
tcub1404n32:
    True
tcub1404n41:
    True
tcub1404n30:
    True
tcub1404n28:
    True
tcub1404n36:
    True

Is this wanted behaviour or am I running into a bug? I was planing on using salt for service discovery (e.g. list all minions with grain role:zookeeper) but this makes it somewhat unreliable. But maybe I'm just failing to understand something about how job management works in salt.

The master is running CentOS 7 with salt-master-2014.1.10-4.el7.noarch (from EPEL) The minions are running Ubuntu 14.04 with salt-minion 2014.1.10+ds-1trusty1 (from SaltStack's ppa).

lloesche avatar Sep 01 '14 13:09 lloesche

I've just started seeing this recently too. Ran sudo salt '*' test.ping and got 3 minions return True. Ran it again a few seconds later, and all 29 responded. Time to do some investigation work.

Interestingly, we have a Python script which runs early every morning, calls cmd.run on every minion, and e-mails me a report. This has been running pretty reliably all year (last failure was one day in early February on an older Salt release which didn't run at all - a different issue). This is currently on Debian Wheezy amd64 in EC2. Master and minions all running the same distro and versions.

           Salt: 2014.1.7
         Python: 2.7.3 (default, Mar 13 2014, 11:03:55)
         Jinja2: 2.6
       M2Crypto: 0.21.1
 msgpack-python: 0.1.10
   msgpack-pure: Not Installed
       pycrypto: 2.6
         PyYAML: 3.10
          PyZMQ: 13.1.0
            ZMQ: 3.2.3

However starting August 30th, I've only been getting reports for 3 or 4 minions at most. So that's 4 report failures so far. This is a very recent development, which makes me theorise that a recent system update might be a contributing factor (we have not changed Salt or its configuration). These were installed just prior to noticing these problems:

2014-08-29 10:41:51 status installed man-db:amd64 2.6.2-1
2014-08-29 10:41:51 status installed libc-bin:amd64 2.13-38+deb7u4
2014-08-29 10:41:53 status installed libc6:amd64 2.13-38+deb7u4
2014-08-29 10:41:54 status installed multiarch-support:amd64 2.13-38+deb7u4
2014-08-29 10:41:57 status installed man-db:amd64 2.6.2-1
2014-08-29 10:41:57 status installed locales-all:amd64 2.13-38+deb7u4
2014-08-29 10:41:58 status installed locales:all 2.13-38+deb7u4

I'm not sure how that could be related - I would have expected much more serious problems if those updates were related, but I have no idea what else could be triggering this sudden surge of discovery failures. We did turn logging up from warning to info a while back (2014-08-19 according to the /etc/salt/master timestamp) but otherwise haven't touched the Salt configuration on master or minions (and certainly haven't upgraded to a new version).

One interesting thing is that according to the minion logs, the cmd.run command does get executed every morning successfully. When I search for the minion job ID on the master, I can see Got return from <hostname> for job 20140830090002421720 for each host too, so it looks like the master did get the result fine, but just refused to display it.

If I run: # zgrep 20140830090002421720 master.1.gz | grep 'Got return from' | tr -s ' ' | cut -d ' ' -f 9 | sort -n I can see that all hosts are accounted for. As for result return times:

# zgrep 20140830090002421720 master.1.gz | grep 'Got return from' | tr -s ' ' | cut -d ' ' -f 1,2
2014-08-30 09:00:04,771
2014-08-30 09:00:06,907
2014-08-30 09:00:07,006
2014-08-30 09:00:09,803
2014-08-30 09:00:14,878
2014-08-30 09:00:14,966
2014-08-30 09:00:18,839
2014-08-30 09:00:20,769
2014-08-30 09:00:22,757
2014-08-30 09:00:29,740
2014-08-30 09:00:31,846
2014-08-30 09:00:32,725
2014-08-30 09:00:33,781
2014-08-30 09:00:35,186
2014-08-30 09:00:38,788
2014-08-30 09:00:39,750
2014-08-30 09:00:44,754
2014-08-30 09:00:45,845
2014-08-30 09:00:46,095
2014-08-30 09:00:47,807
2014-08-30 09:00:49,788
2014-08-30 09:00:55,831
2014-08-30 09:00:56,793
2014-08-30 09:00:57,951
2014-08-30 09:00:59,968
2014-08-30 09:01:00,003
2014-08-30 09:01:02,769

How interesting - execution took over a minute, and it's as if the instances were queried sequentially (as opposed to executing in parallel). If I look back at the results for a previous execution of my daily script that ran successfully for comparison:

# zgrep 20140824090006354508 master.1.gz | grep 'Got return from' | tr -s ' ' | cut -d ' ' -f 1,2
2014-08-24 09:00:06,431
2014-08-24 09:00:06,434
2014-08-24 09:00:06,442
2014-08-24 09:00:06,443
2014-08-24 09:00:06,448
2014-08-24 09:00:06,449
2014-08-24 09:00:06,453
2014-08-24 09:00:06,455
2014-08-24 09:00:06,461
2014-08-24 09:00:06,463
2014-08-24 09:00:06,465
2014-08-24 09:00:06,462
2014-08-24 09:00:06,477
2014-08-24 09:00:06,478
2014-08-24 09:00:06,475
2014-08-24 09:00:06,479
2014-08-24 09:00:06,481
2014-08-24 09:00:06,487
2014-08-24 09:00:06,491
2014-08-24 09:00:06,495
2014-08-24 09:00:06,498
2014-08-24 09:00:06,504
2014-08-24 09:00:06,517
2014-08-24 09:00:06,521
2014-08-24 09:00:06,527
2014-08-24 09:00:06,601
2014-08-24 09:00:06,774

All results returned within the same second! Something very strange has started happening recently, that's for sure. Happy to listen to any thoughts or suggestions. :)

boltronics avatar Sep 02 '14 08:09 boltronics

I also noticed this. Salt master and all salt minions (2014.1.10) are running on CentOS 6.

imtx avatar Sep 02 '14 10:09 imtx

I think this is a duplicate of another issue but I can't find that issue number at the moment. Regardless, I think I can probably explain what's happening here.

Once every 24 hours (by default) the master rotates its AES key. A recently discovered side-effect of this was that the first job sent after this key rotation would not return. A fix has already made it into 2014.7 to resolve this issue and should, I believe, appear in the next release candidate. I can try up dig up the original issue if people are curious.

cachedout avatar Sep 02 '14 15:09 cachedout

Thanks @cachedout. I'm happy to try out the fix (if you can find that bug report you were referring to), but am not entirely convinced. It doesn't (necessarily) explain why my daily cron job has failed consistently the last few days (including again this morning), whereas it was working fine for months prior.

boltronics avatar Sep 02 '14 23:09 boltronics

I am also seeing similar behaviour on 2014.7.0 with zmq 4.0.4

undernocircumstance avatar Sep 04 '14 09:09 undernocircumstance

For the record, I can totally reproduce this on 2014.7.0rc1. First test.ping timed out after a couple of days not using the minion, second one succeeded.

basepi avatar Sep 06 '14 17:09 basepi

As a work-around, we've setup the following cron job in all of our Salt-managed environments. I'm not sure it's now 100% reliable (haven't been using it long enough), but it's certainly a noticeable improvement.

0 * * * * salt '*' test.ping >/dev/null 2>&1

boltronics avatar Sep 10 '14 00:09 boltronics

@boltronics funny, I independently implemented the exact same solution this afternoon :smiley: @basepi In my tests the duration can be even shorter. This morning I was using salt and the first command timed out the ones after worked flawless. This afternoon the same thing happened after only a couple of hours of inactivity. That's when I implemented the cron workaround.

lloesche avatar Sep 10 '14 20:09 lloesche

Me also...I have had this since 2014.1.5 if not earlier...just set a cronjob to see if that helps reduce the 17 dead minions I have.

gzcwnk avatar Sep 11 '14 02:09 gzcwnk

@dariusjs The issue typically happens after a longer period and it seems to be caused by the key rotation as discussed earlier.

wwentland avatar Sep 11 '14 12:09 wwentland

OK, #15722 will ping all minions immediately after a key rotation. Give it a shot and let me know how it goes. Thanks!

cachedout avatar Sep 11 '14 21:09 cachedout

The every-24-hours key rotation is not scheduled for a specific time, so it definitely could happen during the day, explaining the behavior you're seeing.

Anyway, I'd be interested to see if @cachedout's workaround fixes it.

basepi avatar Sep 12 '14 17:09 basepi

Just wanted to add that we experience this bug - the minions sporadically respond (or don't) to commands. A test.ping doesn't fix it for any length of time. If I do salt '*' test.ping repeatedly, I get a different set of machines responding every time. Salt is totally unusable like this.

           Salt: 2014.1.10
         Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
         Jinja2: 2.7.2
       M2Crypto: 0.21.1
 msgpack-python: 0.3.0
   msgpack-pure: Not Installed
       pycrypto: 2.6.1
         PyYAML: 3.10
          PyZMQ: 14.0.1
            ZMQ: 4.0.4

pwaller avatar Sep 18 '14 10:09 pwaller

(and therefore it doesn't seem like #15722 can possibly fix the issue)

pwaller avatar Sep 18 '14 10:09 pwaller

I can reproduce same behaviour on Cento 6.5 with Salt 2014.1.10

spo0nman avatar Sep 18 '14 10:09 spo0nman

@pwaller Do the returns make it to the job cache? You may be running into a different known issue with the event bus, so I'd be interested to know if all the minions are making it to the job cache or not.

basepi avatar Sep 22 '14 17:09 basepi

@basepi it feels like a stupid question, but how would you check that?

Also, was it intended to close this issue?

pwaller avatar Sep 23 '14 13:09 pwaller

@basepi

pwaller@services:~$ salt '*' test.ping

real    0m11.829s
user    0m0.245s
sys 0m0.229s

pwaller@services:~$ salt-run jobs.list_jobs
<snip snip snip>
'20140923131644973219':
  Arguments: []
  Function: test.ping
  StartTime: 2014, Sep 23 13:16:44.973219
  Target: '*'
  Target-type: glob
  User: sudo_pwaller
'20140923131649981037':
  Arguments:
  - '20140923131644973219'
  Function: saltutil.find_job
  StartTime: 2014, Sep 23 13:16:49.981037
  Target: '*'
  Target-type: glob
  User: sudo_pwaller

$ salt-run jobs.lookup_jid 20140923131644973219
machine-1:
    True
machine-2:
    True
machine-etc:
    True
<full complement of machines snipped>

So yes, it does look like everything made it back if that's what you're asking.

pwaller avatar Sep 23 '14 13:09 pwaller

@pwaller We just merged forward into develop, so that commit closed this issue.

That said, if all of your minion returns are making it back to the job cache, then you're running into a different issue than the others in this thread.

We've discovered that at high load, the CLI returns are not always consistent with many minions. However, the job cache has proven to be completely consistent in this case. When minions return, the returns are being handled properly, and then the worker thread that's handling the return fires an event, for which the CLI process is listening. We've discovered that under heavy load some of these events don't make it through to the CLI process.

The problem is that we don't have enough insight into the runtime status of ZMQ to really debug this issue. We've been continuing to try to solve this problem, see if there's a bug in our code. But it also turns out ZMQ doesn't guarantee consistency of that underlying system at load, since it's a pub-sub system. (based on their documentation)

So what's the solution? Our current plan of action is to replace the current event system with one which uses the RAET backend. We think this will give us the consistency and transparency that we need to get this resolved. RAET will be available in salt for the first time in 2014.7.0. It will not release with a flag to just replace the event system while keeping the ZMQ transport, but we will definitely be adding such a flag in short order, once we feel like it's a little more production-ready.

For now, most large installations with which we are familiar are running most commands with --async and then just using the job cache to check returns. Which, in the end, is not quite as convenient as getting it with a single command, but is a pretty easy workaround.

basepi avatar Sep 23 '14 17:09 basepi

Thanks for the explanation, @basepi. Are there any other user interfaces than the CLI for doing this? Also, it's not even a large installation, it's only 7 machines.

pwaller avatar Sep 23 '14 22:09 pwaller