Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix syndic regression #33021

Merged
merged 2 commits into from May 3, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions salt/returners/local_cache.py
Expand Up @@ -100,12 +100,13 @@ def prep_jid(nocache=False, passed_jid=None, recurse_count=0):

# Make sure we create the jid dir, otherwise someone else is using it,
# meaning we need a new jid.
try:
os.makedirs(jid_dir_)
except OSError:
time.sleep(0.1)
if passed_jid is None:
return prep_jid(nocache=nocache, recurse_count=recurse_count+1)
if not os.path.isdir(jid_dir_):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be more correct as the following:

# Make sure we create the jid dir, otherwise someone else is using it,
# meaning we need a new jid.
try:
    os.makedirs(jid_dir_)
except OSError as exc:
    if exc.errno != errno.EEXIST:
        err = 'prep_jid failed creating jid directory: {0}'.format(exc)
        log.error(err)
        raise salt.exceptions.SaltCacheError(err)
    if passed_jid is None:
        # The JID that was just generated is already in use so get a new one.
        time.sleep(0.1)
        return prep_jid(nocache=nocache, recurse_count=recurse_count+1)

try:
os.makedirs(jid_dir_)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to filter for the specific OSError of errno.EEXIST where the JID dir is already created because it is already in-use by another job. All other OSErrors (how about errno.EPERM) should be raised as a real SaltCacheError.

except OSError:
time.sleep(0.1)
if passed_jid is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original bug is that the sleep() is not inside this conditional (if passed_jid is None) for just the case where a JID is generated and we need a new clock tick for a different JID to affect this recursive call.

return prep_jid(nocache=nocache, recurse_count=recurse_count+1)

try:
with salt.utils.fopen(os.path.join(jid_dir_, 'jid'), 'wb+') as fn_:
Expand Down