Merge pull request #48868 from terminalmage/fix-loader-race

Fix race when SIGTERM/SIGINT received while lazyloading a module
This commit is contained in:
Nicole Thomas 2018-08-02 13:13:33 -04:00 committed by GitHub
commit a567666938
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,12 +15,14 @@ import inspect
import tempfile
import functools
import threading
import traceback
import types
from collections import MutableMapping
from zipimport import zipimporter
# Import salt libs
import salt.config
import salt.defaults.exitcodes
import salt.syspaths
import salt.utils.context
import salt.utils.files
@ -1462,6 +1464,17 @@ class LazyLoader(salt.utils.lazy.LazyDict):
self.missing_modules[name] = error
return False
except SystemExit as error:
try:
fn_, _, caller, _ = traceback.extract_tb(sys.exc_info()[2])[-1]
except Exception:
pass
else:
tgt_fn = os.path.join('salt', 'utils', 'process.py')
if fn_.endswith(tgt_fn) and '_handle_signals' in caller:
# Race conditon, SIGTERM or SIGINT received while loader
# was in process of loading a module. Call sys.exit to
# ensure that the process is killed.
sys.exit(salt.defaults.exitcodes.EX_OK)
log.error(
'Failed to import {0} {1} as the module called exit()\n'.format(
self.tag, name