Coding error in salt/utils/cache.py #59437
Labels
Bug
broken, incorrect, or confusing behavior
severity-low
4th level, cosemtic problems, work around exists
Milestone
Description
There seems to be a bug in salt/utils/cache.py. After sending a number jobs with LocalClient.cmd() I guess CacheRegex.sweep() method in this file is called. What seems to be happening is sort() is called on a list containing _sre.SRE_Pattern objects which don't seem to be sortable. By looking at what and how you store in that cache:
it just can't possibly work what you're trying to do in sweep():
These values are lists containing the compiled pattern amongst them. I guess you really intended to sort by the usage time/count or something and here whole lists are compared. You can compare lists but their elements need to be comparable or you need to be lucky and erlier entries on the compared lists are different. Effectively any 2 cache entries with the same usage count (first element on the list) will cause this error, since the compiled pattern seems to be the next item there.
The code below is from Python 3.7 on a Debian box so exception looks a bit different but on 3.6 on RHEL it contains _sre.SRE_Pattern not re.Pattern.
A simple fix should be to do sort(key=lambda i: i[0]) if your aim was to sort by the usage count. There is also creation timestamp at [3] so you may want some more elaborate lambda function there.
Without that fix this eventually ends up with this unhandled exception (stacktrace from Salt 3000.5, some line numbers here and there may be slightly off due to some other patches)
File "/usr/lib/python3.6/site-packages/salt/client/init.py", line 713, in cmd
**kwargs):
File "/usr/lib/python3.6/site-packages/salt/client/init.py", line 1525, in get_cli_event_returns
**kwargs
File "/usr/lib/python3.6/site-packages/salt/client/init.py", line 1102, in get_iter_returns
for raw in ret_iter:
File "/usr/lib/python3.6/site-packages/salt/client/init.py", line 1036, in get_returns_no_block
no_block=True, auto_reconnect=self.auto_reconnect)
File "/usr/lib/python3.6/site-packages/salt/utils/event.py", line 638, in get_event
ret = self._get_event(wait, tag, match_func, no_block)
File "/usr/lib/python3.6/site-packages/salt/utils/event.py", line 561, in _get_event
if any(pmatch_func(ret['tag'], ptag) for ptag, pmatch_func in self.pending_tags):
File "/usr/lib/python3.6/site-packages/salt/utils/event.py", line 561, in
if any(pmatch_func(ret['tag'], ptag) for ptag, pmatch_func in self.pending_tags):
File "/usr/lib/python3.6/site-packages/salt/utils/event.py", line 511, in _match_tag_regex
return self.cache_regex.get(search_tag).search(event_tag) is not None
File "/usr/lib/python3.6/site-packages/salt/utils/cache.py", line 261, in get
self.sweep()
File "/usr/lib/python3.6/site-packages/salt/utils/cache.py", line 246, in sweep
paterns.sort()
TypeError: '<' not supported between instances of '_sre.SRE_Pattern' and '_sre.SRE_Pattern'
Setup
More or less standard Salt 3000.5 installation (with some custom patches, unlikely relevant for the error).
Steps to Reproduce the behavior
Create LocalClient and start sending jobs with cmd(). In my case I use tgt_type="nodegroup" and some kwarg if that makes a difference.
Expected behavior
No exception thrown in that sweep() function.
Versions Report
The text was updated successfully, but these errors were encountered: