bpo-31070: Fix a race condition in importlib _get_module_lock(). (#3033)

This commit is contained in:
Serhiy Storchaka 2017-08-09 14:29:12 +03:00 committed by GitHub
parent 88eee44a91
commit 9b0d1d647e
3 changed files with 1493 additions and 1477 deletions

View File

@ -172,8 +172,18 @@ def _get_module_lock(name):
lock = _DummyModuleLock(name)
else:
lock = _ModuleLock(name)
def cb(_):
del _module_locks[name]
def cb(ref, name=name):
_imp.acquire_lock()
try:
# bpo-31070: Check if another thread created a new lock
# after the previous lock was destroyed
# but before the weakref callback was called.
if _module_locks.get(name) is ref:
del _module_locks[name]
finally:
_imp.release_lock()
_module_locks[name] = _weakref.ref(lock, cb)
finally:
_imp.release_lock()

View File

@ -0,0 +1 @@
Fix a race condition in importlib _get_module_lock().

File diff suppressed because it is too large Load Diff