salt icon indicating copy to clipboard operation
salt copied to clipboard

Cannot create cache_dir salt master exception.

Open ahetmanski opened this issue 11 years ago • 5 comments

Hi guys!

I have configured salt-master with next parameter:

file_roots:
  base:
    - /srv/salt

I have created next directory on my machine: /srv/salt/common

This directory contains next states (only important here): /srv/salt/common/init.sls

include:
  - common.data_helper
  - common.repos

/srv/salt/common/data_helper.sls

save_hosts_data:
  module.run:
    - name: common_nodehelper.nodes_net

/srv/salt/common/repos.sls

/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6:
  file:
    - managed
    - source: salt://common/repos/RPM-GPG-KEY-EPEL-6
    - mode: 644
    - user: root

Then I have created in /srv/salt directory next file: /srv/salt/deploy.sls

include:
  - common

So I use this via salt orchestrate module: salt-run state.orch deploy

It works fine. But once I have found one interesting exception: Installation log

comment: "Run failed on minions: min1
Failures:
    qa137:
      Name: common_nodehelper.nodes_net - Function: module.run - Result: Changed
      Name: /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 - Function: file.managed - Result: Failed

salt-master log

2014-12-08 18:42:10,787 [salt.master                                 ][ERROR   ] Error in function _file_hash:
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/salt/master.py", line 1687, in run_func
    ret = getattr(self, func)(load)
  File "/usr/lib/python2.6/site-packages/salt/fileserver/__init__.py", line 354, in file_hash
    return self.servers[fstr](load, fnd)
  File "/usr/lib/python2.6/site-packages/salt/fileserver/roots.py", line 218, in file_hash
    os.makedirs(cache_dir)
  File "/usr/lib64/python2.6/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 17] File exists: '/var/cache/salt/master/roots/hash/base/common/repos'

Now I cannot repeat this anymore. It appears only one time. I think this is because of the race in salt stack. It cannot create cache_dir sometimes.

I have next SaltStack version:

# salt --versions-report
           Salt: 2014.1.4
         Python: 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
         Jinja2: 2.2.1
       M2Crypto: 0.20.2
 msgpack-python: 0.1.13
   msgpack-pure: Not Installed
       pycrypto: 2.0.1
         PyYAML: 3.10
          PyZMQ: 14.3.1
            ZMQ: 3.2.4

Looking forward to hearing from you. Happy Christmas! Thank you in advance!

ahetmanski avatar Dec 24 '14 14:12 ahetmanski

Thanks for the report. We will be reviewing.

ssgward avatar Dec 29 '14 19:12 ssgward

Hello!

We reproduced this issue again on 2015.5.3:

2015-08-20 04:13:52,464 [salt.master                              ][ERROR   ][10728] Error in function _file_hash:
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/salt/master.py", line 1457, in run_func
    ret = getattr(self, func)(load)
  File "/usr/lib/python2.6/site-packages/salt/fileserver/__init__.py", line 528, in file_hash
    return self.servers[fstr](load, fnd)
  File "/usr/lib/python2.6/site-packages/salt/fileserver/roots.py", line 233, in file_hash
    os.makedirs(cache_dir)
  File "/usr/lib64/python2.6/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 17] File exists: '/var/cache/salt/master/roots/hash/base/common/webui'

There are no defined steps to reproduce: this issue happens from time to time during execution of state.orch runner.

According to code in salt/fileserver/roots.py there is a a validation that cache dir does not exists but for some reason (race?) it appears just before the next line of code tries to create this directory:

231 # make cache directory if it doesn't exist 232 if not os.path.exists(cache_dir): .....something creates directory at this point... 233 os.makedirs(cache_dir)

Maybe it will be reasonable to catch OSError here too? For example:

231 # make cache directory if it doesn't exist 232 if not os.path.exists(cache_dir): try: 233 os.makedirs(cache_dir) except OSError: pass

Looking forward for your reply!

vakulich avatar Aug 20 '15 13:08 vakulich

@vakulich, thanks for the extra info. That is definitely an annoying race condition. I think your proposed fix is probably fine if you want to make a pull request.

jfindlay avatar Aug 20 '15 19:08 jfindlay

Hello, I've got similar issue with 2015.5.3, but in different module:

2015-10-31 00:41:29,354 [salt.master                              ][ERROR   ][6673] Error in function _return:
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/salt/master.py", line 1457, in run_func
    ret = getattr(self, func)(load)
  File "/usr/lib/python2.6/site-packages/salt/master.py", line 1273, in _return
    self.opts, load, event=self.event, mminion=self.mminion)
  File "/usr/lib/python2.6/site-packages/salt/utils/job.py", line 80, in store_job
    mminion.returners[savefstr](load['jid'], load)
  File "/usr/lib/python2.6/site-packages/salt/returners/local_cache.py", line 217, in save_load
    os.makedirs(jid_dir)
  File "/usr/lib64/python2.6/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 17] File exists: '/var/cache/salt/master/jobs/56/271a71f63280e35d933e40f650f791'

I suppose fix should be the same: surround os.makedirs with try-except and silently ignore OSError. On the other hand I think it makes sense to ignore OSError only if errno equals 17 (already exists). So that we don't hide other possible OSError reasons (Permission denied for example).

frizzby avatar Nov 02 '15 13:11 frizzby

@frizzby, see #28545.

jfindlay avatar Nov 03 '15 23:11 jfindlay