GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — importlib race condition allows stale module ref to escape on failure · Issue #143650 · python/cpython Closed Labels interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-importlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionWhen a module import fails, other threads can receive a stale module reference that is no longer in Race condition
Affected code paths
All three have an optimization that skips locking when a module appears already loaded, but none verify the module is still valid after checking Reproducerimport sys import threading import tempfile import os with tempfile.TemporaryDirectory() as tmpdir: sys.path.insert(0, tmpdir) # Module that partially initializes then fails with open(os.path.join(tmpdir, "failing_mod.py"), "w") as f: f.write("import time; time.sleep(0.05); raise RuntimeError('fail')") results = [] def do_import(delay): import time; time.sleep(delay) try: mod = __import__("failing_mod") if "failing_mod" not in sys.modules: results.append("RACE: got module not in sys.modules") except RuntimeError: results.append("ok") t1 = threading.Thread(target=do_import, args=(0,)) t2 = threading.Thread(target=do_import, args=(0.01,)) t1.start(); t2.start(); t1.join(); t2.join() print(results) # May show "RACE" on affected builds Linked PRsActivity
MetadataMetadataAssigneesLabelsinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-importlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |