Log filled with "Exception occurred while Subscriber handling stream: Already reading"
Description of Issue/Question
Hi, on a server running salt-minion and salt-master, the minion's logfile was today filled (quite quickly) with the following message:
2018-08-12 06:25:10,762 [salt.transport.ipc][ERROR ][25008] Exception occurred while Subscriber handling stream: Already reading
2018-08-12 06:25:10,762 [salt.transport.ipc][ERROR ][25008] Exception occurred while Subscriber handling stream: Already reading
2018-08-12 06:25:10,762 [salt.transport.ipc][ERROR ][25008] Exception occurred while Subscriber handling stream: Already reading
2018-08-12 06:25:10,763 [salt.transport.ipc][ERROR ][25008] Exception occurred while Subscriber handling stream: Already reading
2018-08-12 06:25:10,763 [salt.transport.ipc][ERROR ][25008] Exception occurred while Subscriber handling stream: Already reading
2018-08-12 06:25:10,763 [salt.transport.ipc][ERROR ][25008] Exception occurred while Subscriber handling stream: Already reading
2018-08-12 06:25:10,763 [salt.transport.ipc][ERROR ][25008] Exception occurred while Subscriber handling stream: Already reading
2018-08-12 06:25:10,763 [salt.transport.ipc][ERROR ][25008] Exception occurred while Subscriber handling stream: Already reading
2018-08-12 06:25:10,763 [salt.transport.ipc][ERROR ][25008] Exception occurred while Subscriber handling stream: Already reading
2018-08-12 06:25:10,764 [salt.transport.ipc][ERROR ][25008] Exception occurred while Subscriber handling stream: Already reading
Stopping the minion service didn't stop the process writing to the logfile, neither did SIGTERM - I only got rid of it with SIGKILL (PID 25008 here):
$ ps aux | grep [p]ython
root 24851 0.0 0.1 101600 6048 ? S Aug10 0:00 /usr/bin/python /usr/bin/salt-minion
root 24854 0.0 0.2 548420 11264 ? Sl Aug10 0:09 /usr/bin/python /usr/bin/salt-minion
root 25005 0.0 0.1 101600 6412 ? S Aug10 0:00 /usr/bin/python /usr/bin/salt-minion
root 25008 99.9 0.6 549964 27508 ? Sl Aug10 8403:05 /usr/bin/python /usr/bin/salt-minion
Setup
I don't know what's relevant here...
Steps to Reproduce Issue
Don't know either :/
Versions Report
Salt Version:
Salt: 2017.7.2
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 1.5
docker-py: Not Installed
gitdb: 0.5.4
gitpython: 0.3.2 RC1
ioflo: Not Installed
Jinja2: 2.7.2
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: 0.9.1
msgpack-pure: Not Installed
msgpack-python: 0.4.6
mysql-python: 1.2.3
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 2.7.6 (default, Nov 23 2017, 15:49:48)
python-gnupg: Not Installed
PyYAML: 3.10
PyZMQ: 14.4.0
RAET: Not Installed
smmap: 0.8.2
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.0.5
System Versions:
dist: Ubuntu 14.04 trusty
locale: ANSI_X3.4-1968
machine: x86_64
release: 3.19.0-80-generic
system: Linux
version: Ubuntu 14.04 trusty
Same version of minion, master, and common.
was there possibly anything before these log messages appeared that might be more telling as to why this occurred?
Any other reason as to why this would have occured? Where you running a particular command, state, etc?
As far as I know, no manual activity caused this. This looks like the beginning, there don't seem to be any earlier messages:
2018-08-10 13:01:57,661 [salt.log.setup ][WARNING ][24854] Temporary logging is already configured
2018-08-10 13:01:57,720 [salt.log.setup ][WARNING ][24854] Console logging already configured
2018-08-10 13:01:57,721 [salt.log.setup ][WARNING ][24854] Console logging already configured
2018-08-10 13:01:57,723 [salt.log.setup ][WARNING ][24854] Logfile logging already configured
2018-08-10 13:01:57,727 [salt.log.setup ][ERROR ][24854] An un-handled exception was caught by salt's global exception handler:
IOError: [Errno 5] Input/output error
Traceback (most recent call last):
File "/usr/bin/salt-minion", line 26, in <module>
salt_minion()
File "/usr/lib/python2.7/dist-packages/salt/scripts.py", line 204, in salt_minion
minion.start()
File "/usr/lib/python2.7/dist-packages/salt/cli/daemons.py", line 340, in start
super(Minion, self).start()
File "/usr/lib/python2.7/dist-packages/salt/utils/parsers.py", line 1032, in start
self.prepare()
File "/usr/lib/python2.7/dist-packages/salt/cli/daemons.py", line 299, in prepare
self.shutdown(1)
File "/usr/lib/python2.7/dist-packages/salt/cli/daemons.py", line 397, in shutdown
self.__class__.__name__, (exitmsg or '')).strip()))
File "/usr/lib/python2.7/dist-packages/salt/utils/parsers.py", line 1045, in shutdown
self.exit(exitcode, exitmsg)
File "/usr/lib/python2.7/dist-packages/salt/utils/parsers.py", line 268, in exit
optparse.OptionParser.exit(self, status, msg)
File "/usr/lib/python2.7/optparse.py", line 1573, in exit
sys.stderr.write(msg)
IOError: [Errno 5] Input/output error
2018-08-10 13:02:01,413 [salt.log.setup ][WARNING ][25008] Temporary logging is already configured
2018-08-10 13:02:01,473 [salt.log.setup ][WARNING ][25008] Console logging already configured
2018-08-10 13:02:01,473 [salt.log.setup ][WARNING ][25008] Console logging already configured
2018-08-10 13:02:01,475 [salt.log.setup ][WARNING ][25008] Logfile logging already configured
2018-08-10 13:02:01,477 [salt.transport.ipc][ERROR ][25008] Exception occurred while Subscriber handling stream: Already reading
2018-08-10 13:02:01,477 [salt.transport.ipc][ERROR ][25008] Exception occurred while Subscriber handling stream: Already reading
The master's log file contains many stacktraces because it's unable to create temp files, as well as messages like those:
2018-08-14 11:57:41,801 [salt.utils.gitfs ][WARNING ][13836] Update lock file is present for gitfs remote 'http://XXX', skipping. If this warning persists, it is possible that the update process was interrupted, but the lock could also have been manually set. Removing /var/cache/salt/master/gitfs/67557cee86485c172576f530bfb03bbdb4c87c5971858ce20b19388e07b85606/.git/update.lk or running 'salt-run cache.clear_git_lock gitfs type=update' will allow updates to continue for this remote.
2018-08-14 11:58:42,687 [salt.utils.gitfs ][WARNING ][13836] gitfs_global_lock is enabled and update lockfile /var/cache/salt/master/gitfs/67557cee86485c172576f530bfb03bbdb4c87c5971858ce20b19388e07b85606/.git/update.lk is present for gitfs remote 'http://XXX'.
Sorry, I could've added that right at the start, hope this helps!
ping @saltstack/team-transport any ideas here? or follow up questions since this might be difficult to replicate.
This is a race condition somewhere in the event bus client usage on minion side. We use the IPCMessageSubscriber to read the event bus. It's a singleton so there could be 2 instances of the bus client that uses one subscriber and since it's asynchronous, one tries to read while another one didn't done yet. I can't say more without detailed analyze. @furgerf is it easily reproducible on your side? Is it possible to ask you to reproduce this on patched minion code to get better logging?
Hi @DmitryKuzmenko, no unfortunately I have no idea how to reproduce it. By your description, it sounds like you might be able to trigger this more easily by creating a bunch of bus clients and having them read from the same subscriber if that's an option in the relevant code. Let me know if I can help with more info.
@furgerf it's OK. What about the problem, I think we could try to catch this by code review. There are not many places where that subscriber is used. Did you do something on that minion right before? I see the strange exception report in your log 4 seconds before the issue happened. Did you restarted minion manually or by cron? Did minion execute some state or schedule task?
@Ch3LL I propose to mark it as a bug and put to the backlog. If we'd have more reports here, we could increase the severity of this.
@DmitryKuzmenko I've looked into the logs and see that there was some activity before the problem started, someone ran salt '*' cmd.run 'curl ifconfig.me'. There were no restarts though.
Like I mentioned before, this server contains both a minion and a master; the master manages around 40 minions in total. About half of them are currently connected.
@furgerf thank you for the info. I'll review the related code when I'll have time. If you'll reproduce it again any new information is very appreciated.
Any news with this? I was just bitten by it on a couple of minions, eg
# salt-call --versions-report
Salt Version:
Salt: 2018.3.3
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.2
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.7.3
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: 0.21.1
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.4.2
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 2.7.9 (default, Sep 25 2018, 20:42:16)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 14.4.0
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.4.3
ZMQ: 4.0.5
System Versions:
dist: debian 8.11
locale: UTF-8
machine: x86_64
release: 3.16.0-7-amd64
system: Linux
version: debian 8.11
Getting the same here in our setup, about 10 or so of our minions are getting this and filling up drive space rapidly.
FYI - We have about 300 or so minions, so it's not global, and reinstalling did not fix issue.
Started getting this as well. Only a few minions, but it fills up the drive rather quickly causing other issues.
@DmitryKuzmenko seems more people are reporting this so i will increase the severity. any idea as to when you can get to this issue? I know its currently on your backlog due to higher priority issues.
Had some time today to work on this. I confirmed my thinking I wrote here above. Tomorrow I'll provide the description and solution.
I have no any code yet, but I promised to post an update and I'm doing this: the main problem is that IPCMessageSubscriber is a singleton. It's used by event that could be instantiated anywhere just to wait for some event, handle it and forget. So we can have a number of event instances at once. All of them will share one subscriber. If a number of instances run read_async simultaneously all will call stream.read_bytes that will fail for all subsequent calls if the first one isn't done yet. Moreover it conforms with the subscriber pattern, all the instance have to get the same data if some received.
The simplest way to fix this is to make the IPCMessageSubscriber non-sigleton. Here we need to make IPCClient a non-singleton and slightly rewrite IPCMessageClient to implement singleton by itself (or make it non-singleton too). This could have a performance impact as well.
One more of my minds is to split singleton to non-singleton handler class strong referencing the singleton instance and singleton weak referencing the handlers. This will allow singleton to know who is waiting for the event data and pass data to all event objects.
Let me some time to think about the best solution. I'll provide one soon.
@saltstack/team-core any thoughts about this ^^^ are very appreciated.
I've started to see this on a number (15-20%) of minions in my fleet as well. salt-minion doesn't properly die when restarted via systemd, requiring a SIGTERM.
This fills up my disks very rapidly, which of course causes other issues.
Seeing this regularly reoccur across our entire fleet at regular intervals of a week or so. Exactly as described. The only way to resolve this is to force kill the minion processes, as they no longer respond to the master or systemd trying to shut them down.
It looks like service restart cause the issue, because minion sometimes can not properly die on SIGTERM, which leaves some processes hanged that must be killed manually.
2018-12-05 05:10:11,000 [salt.utils.parsers:1053][WARNING ][2280007] Minion received a SIGTERM. Exiting.
2018-12-05 05:10:11,531 [salt.log.setup :441 ][WARNING ][2280007] Temporary logging is already configured
2018-12-05 05:10:11,624 [salt.log.setup :494 ][WARNING ][2280007] Console logging already configured
2018-12-05 05:10:11,626 [salt.log.setup :494 ][WARNING ][2280007] Console logging already configured
2018-12-05 05:10:11,830 [salt.log.setup :569 ][WARNING ][2280007] Logfile logging already configured
2018-12-05 05:10:11,833 [salt.transport.ipc:723 ][ERROR ][2280007] Exception occurred while Subscriber handling stream: Already reading
2018-12-05 05:10:11,833 [salt.transport.ipc:723 ][ERROR ][2280007] Exception occurred while Subscriber handling stream: Already reading
2018-12-05 05:10:11,834 [salt.transport.ipc:723 ][ERROR ][2280007] Exception occurred while Subscriber handling stream: Already reading
2018-12-05 05:10:11,834 [salt.transport.ipc:723 ][ERROR ][2280007] Exception occurred while Subscriber handling stream: Already reading
2018-12-05 05:10:11,834 [salt.transport.ipc:723 ][ERROR ][2280007] Exception occurred while Subscriber handling stream: Already reading
2018-12-05 05:10:11,834 [salt.transport.ipc:723 ][ERROR ][2280007] Exception occurred while Subscriber handling stream: Already reading
We have this issue on cPanel servers, and trigger for this is daily package update ( upcp / rpmup ) that also auto restart services that are using some updated packages. For example, if python is updated on this cron job it will find all processes using old python version, and will auto restart such services, and salt-minion is one of them, but in some cases salt-minion restart just does not work properly and leave hanged processes. Maybe python update does really cause the restart issue, but I am not sure because ~500 packages were updated on this rpmup execution.
- Processing command `/usr/local/cpanel/scripts/find_outdated_services --auto`
[/usr/local/cpanel/scripts/find_outdated_services] Looking for outdated services …
[/usr/local/cpanel/scripts/find_outdated_services]
[/usr/local/cpanel/scripts/find_outdated_services] The system found 28 outdated services:
...
[/usr/local/cpanel/scripts/find_outdated_services] salt-minion
...
[/usr/local/cpanel/scripts/find_outdated_services] Restarting “salt-minion” …
[/usr/local/cpanel/scripts/find_outdated_services] The system has restarted “salt-minion”.
...
Untill this salt-minion issue is resolved, temporary solution for this on cPanel servers is to add salt-minion to file /etc/cpanel/local/ignore_outdated_services to prevent auto restarts.
@deyanx I think that while cPanel does restart salt-minion, that's just a trigger for the underlying problem. We see this on cPanel servers too, but even with find_outdated_services ignoring salt-minion, any other attempt to restart salt-minion via systemctl causes the same behaviour.