Bug 15957

Summary: AB-INT: importlib deadlock issue on older python versions
Product: [QA/Testing] Functional (self) Testing Reporter: Mathieu Dubois-Briand <mathieu.dubois-briand>
Component: oe-selftestAssignee: Unassigned <unassigned>
Status: NEW --- QA Contact:
Severity: normal    
Priority: Medium CC: antonin.godard, JPEWhacker, randy.macleod, richard.purdie, yoann.congal
Version: unspecified   
Target Milestone: 6.1   
Hardware: x86   
OS: Multiple   
See Also: https://bugzilla.yoctoproject.org/show_bug.cgi?id=16453
Whiteboard: AB-INT
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description Mathieu Dubois-Briand 2025-08-21 06:53:04 UTC
I'm not really sure how to understand this failure and what is the root cause here.

First we have:

     75 2025-08-17 01:29:52,082 - oe-selftest - INFO - testtools.testresult.real._StringException: Traceback (most recent call last):
     76   File "/srv/pokybuild/yocto-worker/qemuarm64-tc/build/meta/lib/oeqa/core/case.py", line 40, in _oeSetUpClass
     77     clss.setUpClassMethod()
     78   File "/srv/pokybuild/yocto-worker/qemuarm64-tc/build/meta/lib/oeqa/selftest/cases/meta_ide.py", line 23, in setUpClass
     79     bb_vars = get_bb_vars(['MACHINE_ARCH', 'TARGET_VENDOR', 'TARGET_OS', 'DEPLOY_DIR_IMAGE', 'COREBASE'])
     80   File "/srv/pokybuild/yocto-worker/qemuarm64-tc/build/meta/lib/oeqa/utils/commands.py", line 250, in get_bb_vars
     81     bbenv = get_bb_env(target, postconfig=postconfig)
     82   File "/srv/pokybuild/yocto-worker/qemuarm64-tc/build/meta/lib/oeqa/utils/commands.py", line 246, in get_bb_env
     83     return bitbake("-e", postconfig=postconfig).output
     84   File "/srv/pokybuild/yocto-worker/qemuarm64-tc/build/meta/lib/oeqa/utils/commands.py", line 236, in bitbake
     85     return runCmd(cmd, ignore_status, timeout, output_log=output_log, **options)
     86   File "/srv/pokybuild/yocto-worker/qemuarm64-tc/build/meta/lib/oeqa/utils/commands.py", line 214, in runCmd
     87     raise AssertionError("Command '%s' returned non-zero exit status %d:\n%s" % (command, result.status, exc_output))
     88 AssertionError: Command 'bitbake  -e' returned non-zero exit status 1:
     89 NOTE: Reconnecting to bitbake server...
     90 ERROR: Unable to parse <frozen importlib._bootstrap>
     91 Traceback (most recent call last):
     92   File "<frozen importlib._bootstrap>", line 1024, in _find_and_load
     93   File "<frozen importlib._bootstrap>", line 171, in __enter__
     94   File "<frozen importlib._bootstrap>", line 123, in acquire
     95 KeyError: 140462603003456

But we also have this, later in the log:

    105 Exception in thread Thread-13 (_run_test):
    106 Traceback (most recent call last):
    107   File "/srv/pokybuild/yocto-worker/qemuarm64-tc/build/meta/lib/oeqa/core/utils/concurrencytest.py", line 234, in _run_test
    108     testserver.run(process_result)
    109   File "/usr/lib/python3/dist-packages/subunit/__init__.py", line 1197, in run
    110     protocol.lineReceived(line)
    111   File "/usr/lib/python3/dist-packages/subunit/__init__.py", line 567, in lineReceived
    112     self._state.lineReceived(line)
    113   File "/usr/lib/python3/dist-packages/subunit/__init__.py", line 404, in lineReceived
    114     self.details_parser.lineReceived(line)
    115   File "/usr/lib/python3/dist-packages/subunit/details.py", line 42, in lineReceived
    116     self._state.endDetails()
    117   File "/usr/lib/python3/dist-packages/subunit/__init__.py", line 400, in endDetails
    118     self.parser.client.stopTest(self.parser._current_test)
    119   File "/usr/lib/python3/dist-packages/testtools/testresult/real.py", line 1537, in stopTest
    120     return self.decorated.stopTest(test)
    121   File "/usr/lib/python3/dist-packages/testtools/testresult/real.py", line 232, in stopTest
    122     super().stopTest(test)
    123   File "/usr/lib/python3.10/unittest/result.py", line 80, in stopTest
    124     self._restoreStdout()
    125   File "/usr/lib/python3.10/unittest/result.py", line 99, in _restoreStdout
    126     self._stdout_buffer.seek(0)
    127 AttributeError: 'NoneType' object has no attribute 'seek'
Comment 1 Mathieu Dubois-Briand 2025-08-21 06:55:22 UTC
qemuarm64-tc ubuntu2204-vk-1 master completed at 2025-08-17 11:34:38+00:00
https://autobuilder.yoctoproject.org/valkyrie/#/builders/5/builds/2140/steps/12/logs/stdio
Comment 2 Randy MacLeod 2025-08-21 14:44:16 UTC
Richard thinks that this is a python bug in ubu-22.04 that has been fixed in newer versions of python. 

Monitor for now,

The main error is the KeyError
Comment 3 Randy MacLeod 2026-04-23 15:17:34 UTC
Has't happen. Might be fixed by weekly builder distro updates.
Comment 4 Joshua Watt 2026-05-28 19:50:03 UTC
This was seen again in https://bugzilla.yoctoproject.org/show_bug.cgi?id=16296 (which is now closed as a duplicate of this bug).
Comment 5 Joshua Watt 2026-05-28 19:50:56 UTC
*** Bug 16296 has been marked as a duplicate of this bug. ***
Comment 6 Yoann Congal 2026-06-30 21:33:26 UTC
oe-selftest-debian debian11-vk-1 scarthgap completed at 2026-06-30 18:59:51+00:00
https://autobuilder.yoctoproject.org/valkyrie/?#/builders/35/builds/4176

 $ ssh debian11-vk-1.yocto.io python3 --version
Python 3.9.2

I think the upstream bug is "importlib lock race issue in deadlock handling code" · Issue #91351 · python/cpython
https://github.com/python/cpython/issues/91351
=> Linked PR:
gh-91351: Fix some bugs in importlib handling of re-entrant imports by exarkun · Pull Request #94504 · python/cpython
https://github.com/python/cpython/pull/94504

=> Merge commit:
gh-91351: Fix some bugs in importlib handling of re-entrant imports (… · python/cpython@3325f05
https://github.com/python/cpython/commit/3325f054e33b318aa56b74472f76a56b8afc0510

=> in python >= 3.12

Note: I've created #16335 "Create more fine-grained buildtools", with the idea of creating a buildtool-python3 to install a fixed python where host python3 has this bug.
Comment 7 Yoann Congal 2026-06-30 21:39:19 UTC
Looking through https://errors.yoctoproject.org/Errors/Search/?query=frozen+importlib._bootstrap, I found others instances:
oe-selftest-fedora stream9-vk-1 scarthgap completed at 2026-06-24 13:17:33+00:00
https://autobuilder.yoctoproject.org/valkyrie/?#/builders/48/builds/3965/steps/15/logs/stdio
oe-selftest-debian ubuntu2204-vk-1 scarthgap completed at 2026-04-07 00:36:39+00:00
https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/3612/steps/15/logs/stdio
oe-selftest-debian debian11-vk-1 whinlatter completed at 2026-03-29 11:53:50+00:00
https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/3545/steps/15/logs/stdio

Note: the link to this bug is not easy to notice because the reported error appears later and is not always the same.