salt icon indicating copy to clipboard operation
salt copied to clipboard

Recursion error in onchanges_any when file not touched

Open wschmrdrNS opened this issue 8 years ago • 5 comments

Description of Issue/Question

On running a command using onchanges_any for a file list, if the file wasn't up for a potential change, a RuntimeError Traceback for maximum recursion is received in 2018.3, while in the 2017.7 builds, the file is inferred as not having been changed (which is what I was expecting).

Setup

(Please provide relevant configs and/or SLS files (Be sure to remove sensitive info).)

/lib/systemd/system/api.service:
  file.managed:
    - source: salt://files/api.service.in
    - user: root
    - mode: 644
    - template: jinja
    - context: {{ pillar }}

{% if grains.id in salt['pillar.get']('master:nodegroups:staging', []) %]

/lib/systemd/system/smtpd.service:
  file.managed:
    - source: salt://files/smtpd.service.in
    - user: root
    - mode: 644
    - template: jinja
    - context: {{ pillar }}

{% endif %}

systemd-reload:
  cmd.run:
    - name: systemctl --system daemon-reload
    - onchanges_any:
      - file: /lib/systemd/system/api.service
      - file: /lib/systemd/system/smtpd.service

Steps to Reproduce Issue

(Include debug logs if possible and relevant.) I ran the SLS snippet against two minions: one within master:nodegroups:staging, and one not within. The one within had no issue. The one not within had the following traceback:

    The minion function caused an exception: Traceback (most recent call last):
      File "/usr/lib/python2.7/dist-packages/salt/minion.py", line 1600, in _thread_return
        return_data = minion_instance.executors[fname](opts, data, func, args, kwargs)
      File "/usr/lib/python2.7/dist-packages/salt/executors/direct_call.py", line 12, in execute
        return func(*args, **kwargs)
      File "/usr/lib/python2.7/dist-packages/salt/modules/state.py", line 749, in apply_
        return highstate(**kwargs)
      File "/usr/lib/python2.7/dist-packages/salt/modules/state.py", line 1055, in highstate
        orchestration_jid=orchestration_jid)
      File "/usr/lib/python2.7/dist-packages/salt/state.py", line 3881, in call_highstate
        return self.state.call_high(high, orchestration_jid)
      File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2706, in call_high
        ret = self.call_chunks(chunks)
      File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2096, in call_chunks
        running = self.call_chunk(low, running, chunks)
      File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2524, in call_chunk
        running = self.call_chunk(low, running, chunks)
(repeating the last call until the end of the traceback below)
      File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2524, in call_chunk
        running = self.call_chunk(low, running, chunks)
      File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2407, in call_chunk
        low = self._mod_aggregate(low, running, chunks)
      File "/usr/lib/python2.7/dist-packages/salt/state.py", line 796, in _mod_aggregate
        agg_opt = self.functions['config.option']('state_aggregate')
      File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1142, in __getitem__
        func = super(LazyLoader, self).__getitem__(item)
      File "/usr/lib/python2.7/dist-packages/salt/utils/lazy.py", line 97, in __getitem__
        if key not in self._dict and not self.loaded:
    RuntimeError: maximum recursion depth exceeded in cmp

Versions Report

(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.) Master:

Salt Version:
           Salt: 2018.3.0
 
Dependency Versions:
           cffi: 1.5.2
       cherrypy: Not Installed
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: 0.26.0
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: 2.14
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: 0.26.3
         Python: 2.7.12 (default, Dec  4 2017, 14:50:18)
   python-gnupg: 2.2.0
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4
 
System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-109-generic
         system: Linux
        version: Ubuntu 16.04 xenial

Minion:

Salt Version:
           Salt: 2018.3.0
 
Dependency Versions:
           cffi: 1.9.1
       cherrypy: Not Installed
       dateutil: 2.7.2
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: 2.17
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Dec  4 2017, 14:50:18)
   python-gnupg: 0.3.8
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4
 
System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-101-generic
         system: Linux
        version: Ubuntu 16.04 xenial

Salt 2017.7.5 was also tested (master and minion matching), and there is no issue on either minion for that version.

wschmrdrNS avatar Apr 18 '18 15:04 wschmrdrNS

Might be related to what was fixed in https://github.com/saltstack/salt/pull/46788

garethgreenaway avatar Apr 18 '18 15:04 garethgreenaway

I just ran into this bug as well. onchanges_in with one file does not cause the problem. onchanges_any with two files and I get the recursion error.

aerocms avatar Jan 26 '19 18:01 aerocms

Found a difference in error handling with onchanges vs onchanges_any. I had a broken logic with some defined requisites missing and onchanges_any gives me a recursion error:

                  The minion function caused an exception: Traceback (most recent call last):
                File "/opt/behavox/.local/lib/python3.6/site-packages/salt/minion.py", line 1660, in _thread_return
                  return_data = minion_instance.executors[fname](opts, data, func, args, kwargs)
                File "/opt/behavox/.local/lib/python3.6/site-packages/salt/executors/direct_call.py", line 12, in execute
                  return func(*args, **kwargs)
                File "/opt/behavox/.local/lib/python3.6/site-packages/salt/modules/state.py", line 1340, in sls
                  ret = st_.state.call_high(high_, orchestration_jid)
                File "/opt/behavox/.local/lib/python3.6/site-packages/salt/state.py", line 2789, in call_high
                  ret = self.call_chunks(chunks)
                File "/opt/behavox/.local/lib/python3.6/site-packages/salt/state.py", line 2151, in call_chunks
                  running = self.call_chunk(low, running, chunks)
                File "/opt/behavox/.local/lib/python3.6/site-packages/salt/state.py", line 2588, in call_chunk
                  running = self.call_chunk(low, running, chunks)
                File "/opt/behavox/.local/lib/python3.6/site-packages/salt/state.py", line 2588, in call_chunk
                  running = self.call_chunk(low, running, chunks)
                File "/opt/behavox/.local/lib/python3.6/site-packages/salt/state.py", line 2588, in call_chunk
                  running = self.call_chunk(low, running, chunks)
                [Previous line repeated 932 more times]
                File "/opt/behavox/.local/lib/python3.6/site-packages/salt/state.py", line 2468, in call_chunk
                  low = self._mod_aggregate(low, running, chunks)
                File "/opt/behavox/.local/lib/python3.6/site-packages/salt/state.py", line 828, in _mod_aggregate
                  agg_opt = self.functions['config.option']('state_aggregate')
                File "/opt/behavox/.local/lib/python3.6/site-packages/salt/loader.py", line 1196, in __getitem__
                  func = super(LazyLoader, self).__getitem__(item)
                File "/opt/behavox/.local/lib/python3.6/site-packages/salt/utils/lazy.py", line 98, in __getitem__
                  if self._missing(key):
              RecursionError: maximum recursion depth exceeded

while onchanges correctly prints the issue:

                   Comment: The following requisites were not found:
                                               onchanges:
                                                   file: formula.hadoop.configs.rack_awareness.config
                                                   file: formula.hadoop.configs.rack_awareness.script

Everything was in 2019.02

Oloremo avatar Jun 12 '19 19:06 Oloremo

I also ran into something similar that seemed to be triggered by onfail_any with only one argument. I couldn't pin it down and reproduce later as our setup is somewhat complicated but the orchestrate crashed on:

[INFO    ] Completed state [apply_state_on_all_master_nodes_after_bootstrap] at time 14:08:58.040245 (duration_in_ms=106790.905)
Exception occurred in runner state.orchestrate: Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/client/mixins.py", line 377, in low
    data['return'] = func(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/runners/state.py", line 128, in orchestrate
    orchestration_jid=orchestration_jid)
  File "/usr/lib/python2.7/dist-packages/salt/modules/state.py", line 1340, in sls
    ret = st_.state.call_high(high_, orchestration_jid)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2789, in call_high
    ret = self.call_chunks(chunks)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2151, in call_chunks
    running = self.call_chunk(low, running, chunks)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2588, in call_chunk
    running = self.call_chunk(low, running, chunks)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2588, in call_chunk
...
    running = self.call_chunk(low, running, chunks)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2588, in call_chunk
    running = self.call_chunk(low, running, chunks)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2588, in call_chunk
    running =[INFO    ] Runner completed: 20190830140710385358
 self.call_chunk(low, running, chunks)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2588, in call_chunk
    running = self.call_chunk(low, running, chunks)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2588, in call_chunk
    running = self.call_chunk(low, running, chunks)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2588, in call_chunk
    running = self.call_chunk(low, running, chunks)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2588, in call_chunk
    running = self.call_chunk(low, running, chunks)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2588, in call_chunk
    running = self.call_chunk(low, running, chunks)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2588, in call_chunk
    running = self.call_chunk(low, running, chunks)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2588, in call_chunk
    running = self.call_chunk(low, running, chunks)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2588, in call_chunk
    running = self.call_chunk(low, running, chunks)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2588, in call_chunk
    running = self.call_chunk(low, running, chunks)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2468, in call_chunk
    low = self._mod_aggregate(low, running, chunks)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 828, in _mod_aggregate
    agg_opt = self.functions['config.option']('state_aggregate')
  File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1196, in __getitem__
    func = super(LazyLoader, self).__getitem__(item)
  File "/usr/lib/python2.7/dist-packages/salt/utils/lazy.py", line 101, in __getitem__
    if key not in self._dict and not self.loaded:
RuntimeError: maximum recursion depth exceeded in cmp

this was salt 2019.2.0 (Fluorine), python2, debian buster

vdloo avatar Aug 30 '19 14:08 vdloo

Cannot reproduce on 3006.x, 3007.x, 3008.x, or master. Missing onchanges_any requisite now reports cleanly instead of recursing. Fixed on 3006.x/3007.x by commit 13e45028ee9 (lost-requisite check covers _any variants) and on 3008.x/master by #66135 (compile-time validation in salt/utils/requisite.py).

dwoz avatar Jun 29 '26 21:06 dwoz