minion exits with Ctrl-C after running test.ping
I was on IRC the other day talking about connection problems. I use debian wheezy and I built the package from sid (0.12.1). I then upgraded to 0.13.1 but still experienced problems from the machines that use a particular ISP. UtahDave suggested that I update zeromq to a newer version. The version of zeromq that is currently in wheezy is at 2.2.0. I was able to find a newer version of zeromq from which I could build a package (3.2.2). I then also backported pyzmq to version 13.0.0. All of my packages seemed to build and install just fine. My package builds can be found here: http://debrepos.littledebian.org/paella .
Here is the master:
daddy:/etc# salt --versions-report
Salt: 0.13.0-405-g6e2896d
Python: 2.7.3 (default, Jan 2 2013, 13:56:14)
Jinja2: 2.6
M2Crypto: 0.21.1
msgpack-python: 0.1.10
msgpack-pure: not installed
pycrypto: 2.6
PyYAML: 3.10
PyZMQ: 13.0.0
This is from a minion after I start it and run test.ping on the master:
[INFO ] Minion is starting as user 'root'
[DEBUG ] Minion "bard" trying to tune in
[DEBUG ] Minion PUB socket URI: ipc:///var/run/salt/minion/minion_event_3b2a0e2c2ace2dc6aa80cbefa151205a_pub.ipc
[DEBUG ] Minion PULL socket URI: ipc:///var/run/salt/minion/minion_event_3b2a0e2c2ace2dc6aa80cbefa151205a_pull.ipc
[INFO ] User sudo_umeboshi Executing command test.ping with jid 20130302230826543116
[DEBUG ] Command details {'tgt_type': 'glob', 'jid': '20130302230826543116', 'tgt': '*', 'ret': '', 'user': 'sudo_umeboshi', 'arg': [], 'fun': 'test.ping'}
[INFO ] Returning information for job: 20130302230826543116
[INFO ] User sudo_umeboshi Executing command saltutil.find_job with jid 20130302230836760840
[DEBUG ] Command details {'tgt_type': 'glob', 'jid': '20130302230836760840', 'tgt': '*', 'ret': '', 'user': 'sudo_umeboshi', 'arg': ['20130302230826543116'], 'fun': 'saltutil.find_job'}
[INFO ] Executing command 'ps -efH' in directory '/root'
[DEBUG ] output: UID PID PPID C STIME TTY TIME CMD
root 2 0 0 Feb04 ? 00:00:00 [kthreadd]
<snip>
[INFO ] Returning information for job: 20130302230836760840
[WARNING ] Stopping the Salt Minion
[WARNING ] Exiting on Ctrl-c
I edited salt/init.py. In Minion.start(), I removed excepting KeyboardInterrupt from the try loop. It seems that pyzmq is raising the KeyboardInterrupt, although I can assure you that no keys are being pressed. Here is the traceback I got after telling salt not to handle it.
Traceback (most recent call last):
File "./scripts/salt-minion", line 14, in <module>
salt_minion()
File "/freespace/home/umeboshi/workspace/others/salt/salt/scripts.py", line 29, in salt_minion
minion.start()
File "/freespace/home/umeboshi/workspace/others/salt/salt/__init__.py", line 189, in start
self.minion.tune_in()
File "/freespace/home/umeboshi/workspace/others/salt/salt/minion.py", line 769, in tune_in
self.opts['loop_interval'] * 1000)
File "/usr/lib/python2.7/dist-packages/zmq/sugar/poll.py", line 97, in poll
return zmq_poll(list(self.sockets.items()), timeout=timeout)
File "_poll.pyx", line 116, in zmq.core._poll.zmq_poll (zmq/core/_poll.c:1474)
File "checkrc.pxd", line 20, in zmq.core.checkrc._check_rc (zmq/core/_poll.c:1824)
KeyboardInterrupt
I looked at checkrc here: https://github.com/zeromq/pyzmq/blob/master/zmq/core/checkrc.pxd
Apparently, 0mq is raising KeyboardInterrupt after receiving EINTR, which means that the proc was interrupted by a signal. I can confirm that these interruptions are not from the keyboard, but I still can't determine what is causing the interruption.
I think this quick and dirty hack will solve my problems temporarily.
diff --git a/salt/minion.py b/salt/minion.py
index 4e590b3..a14e024 100644
--- a/salt/minion.py
+++ b/salt/minion.py
@@ -783,6 +783,9 @@ class Minion(object):
self.epub_sock.send(package)
except Exception:
pass
+ except KeyboardInterrupt:
+ log.warn("KeyboardInterrupt raised by zmq")
+ continue
except zmq.ZMQError:
# This is thrown by the inturupt caused by python handling the
# SIGCHLD. This is a safe error and we just start the poll
Thanks for the detailed report! We'll get on this right away.
@umeboshi2, I think this might have to do with sigchld handling, can you set: multiprocessing: False in the minion config and see if this makes the problem go away? I have not been able to reproduce this so far, thanks for the help!
That seems to work. I still this is still pyzmq misinterpreting EINTR and raising the KeyboardInterrupt when another signal responsible for the interruption.
This also seems to be fixing the problem that I was having when using salt -I 'key:value' do.something. Sometimes I would lose connections to minions shortly after refresh_pillar, and sometimes the connections would be lost after -I targeting, however I couldn't force or reliably reproduce this, yet there was about a 40-60% chance of encountering the problem on a given minion. (I left one minion with multiprocessing: True on purpose, since my hack is already working around the Ctrl-C problem, and the behavior of losing connectivity is consistent on this host, while the hosts that have MP: False are acting more reliably now.)
Python is inconsistent in his handling of EINTR. Search http://bugs.python.org/ for EINTR and you can see examples like
http://bugs.python.org/issue12268
That was only closed on 2013-02-01. So some system calls are retried but others are not on EINTR. In particular one that goofed up a project of mine was calling "select" which last I checked is still not handled properly (Python implementation : source code/Modules/selectmodule.c). A library I was using had called select and incorrectly handled the exception. It passing up an exception that the connection had been dropped even though it really had not. That sounds similar to your KeyboardInterrupt.
For my project the process was likely being interrupted by sigchld as I had many children processes completing all the time. So I saw many of these problems.
The "right thing to do" is for python to handle this properly. The next best thing is for the lowest layer library to handle it properly and not pass up a bogus exception.
For the record, I reproduced this (accidentally) today on OSX off latest develop.
sudo salt --versions-report
Salt: 0.13.0-512-g61dc4b3
Python: 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
Jinja2: 2.6
M2Crypto: 0.21.1
msgpack-python: 0.2.4
msgpack-pure: not installed
pycrypto: 2.6
PyYAML: 3.10
PyZMQ: 13.0.0
I saw this today on one minion running Salt version 0.13.1 on Ubuntu 12.10. Unfortunately I don't have access to that machine anymore (it was during a lab at the Stockholm Python User Group meetup).
Can you guys try this commit? I think it handles it, but I can't reproduce this locally as well
It seems to be fixed, but I couldn't reproduce it super consistently, so we'll have to see.
It will be a while before I will be able to test this, but I'll let you know the results, as this problem was showing up consistently for me.
Thanks, we will get this into 0.13.2, hopefully it fixes everything
Sorry, it's not fixed. The process does not die now, but it stays in an unusable state.
##### FIRST PING:
[INFO ] User root Executing command test.ping with jid 20130308094228904310
[DEBUG ] Command details {'tgt_type': 'glob', 'jid': '20130308094228904310', 'tgt': 'saltlps.gr1.inaccess.com', 'ret': '', 'user': 'root', 'arg': [], 'fun': 'test.ping'}
[INFO ] Returning information for job: 20130308094228904310
##### SECOND PING (never got a reply):
[INFO ] User root Executing command test.ping with jid 20130308094234659946
[DEBUG ] Command details {'tgt_type': 'glob', 'jid': '20130308094234659946', 'tgt': 'saltlps.gr1.inaccess.com', 'ret': '', 'user': 'root', 'arg': [], 'fun': 'test.ping'}
[CRITICAL] Traceback (most recent call last):
File "/usr/lib/pymodules/python2.6/salt/minion.py", line 783, in tune_in
self._handle_payload(payload)
File "/usr/lib/pymodules/python2.6/salt/minion.py", line 296, in _handle_payload
'clear': self._handle_clear}[payload['enc']](payload['load'])
File "/usr/lib/pymodules/python2.6/salt/minion.py", line 332, in _handle_aes
self._handle_decoded_payload(data)
File "/usr/lib/pymodules/python2.6/salt/minion.py", line 377, in _handle_decoded_payload
process.start()
File "/usr/lib/python2.6/multiprocessing/process.py", line 99, in start
_cleanup()
File "/usr/lib/python2.6/multiprocessing/process.py", line 53, in _cleanup
if p._popen.poll() is not None:
File "/usr/lib/python2.6/multiprocessing/forking.py", line 106, in poll
pid, sts = os.waitpid(self.pid, flag)
OSError: [Errno 10] No child processes
this happens every single time. Strangely when run via strace it doesn't happen, perhaps strace does some signal handling.
In any case ignoring SIGCHLD seems wrong, someone should wait() for it or it will become a zombie. From the trace it seems that indeed someone tries to waitpid, not sure why.
Replacing SIG_IGN with SIG_DFL seems to solve the issue, and no more deaths occur but I cannot explain why since the default action for SIGCHLD is "Ignore" according to signal(7). Perhaps someone has called sigaction(2) with SA_NOCLDWAIT for SIGCHLD.
libzmq: 3.2.2 python-zmq: 13.0.0 OS: debian 6
UPDATE: I dont have python knowledge but it seems the following is happening: python's multiprocessing/forking.py is executing a non-hanging waitpid() (I don't know why and when, perhaps periodically) if SIGCHLD is set to SIG_IGN, then this waitpid fails with ECHILD (according to man waitpid) and hence the crash. if SIGCHLD is set to SIG_DFL then this waitpid succeeds, and the process is not zombified.
So providing multiprocessing/forking calls waitpid, set this to SIG_DFL
This is a pyzmq(zmq?) issue, see https://github.com/zeromq/pyzmq/pull/338
Do not install pyzmq==13.0.0 and your good to go, ie:
pip install pyzmq<13.0.0
@s0undt3ch the solution cannot be to install an old version. Salt 12.1 also has no problem. This is a problem in salt's signal handling it must be fixed.
I would like to think that pyzmq issue is both serious enough and the fix trivial enough to hopefully expect a bugfix release shortly that we can build against.
I already have zeromq 3.2.2 backported to squeeze on soon-to-be official salt repo. I would like to be able to use recommended pyzmq 13~ along with it. (There are other problems with backporting pyzmq).
If no bugfix release occurs in the near future, there are ways to make sure the pyzmq code is proper. For debian/ubuntu, just simply patch 13.0.0 and put the built packages on the debian repo. For pip, make a github fork of zeromq/pyzmq and add a dependency_link to setup.py . That would work as a temporary solution until a new upstream release is available.
@umeboshi2 the KeyboardInterrupt is a pyzmq issue, we're just getting hit by hit because we need to handle signals.
I agree and stated that earlier. In fact my proposal is to either wait for pyzmq bugfix release or make temporary fork.