Skip to content

Commit f3b8917

Browse files
[3.6] bpo-31070: Fix a race condition in importlib _get_module_lock(). (GH-3033). (#3038)
(cherry picked from commit 9b0d1d6)
1 parent 33460fa commit f3b8917

File tree

3 files changed

+1494
-1479
lines changed

3 files changed

+1494
-1479
lines changed

Lib/importlib/_bootstrap.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,18 @@ def _get_module_lock(name):
172172
lock = _DummyModuleLock(name)
173173
else:
174174
lock = _ModuleLock(name)
175-
def cb(_):
176-
del _module_locks[name]
175+
176+
def cb(ref, name=name):
177+
_imp.acquire_lock()
178+
try:
179+
# bpo-31070: Check if another thread created a new lock
180+
# after the previous lock was destroyed
181+
# but before the weakref callback was called.
182+
if _module_locks.get(name) is ref:
183+
del _module_locks[name]
184+
finally:
185+
_imp.release_lock()
186+
177187
_module_locks[name] = _weakref.ref(lock, cb)
178188
finally:
179189
_imp.release_lock()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a race condition in importlib _get_module_lock().

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy