Skip to content

tentacle: cephadm/tests: pre-import tracemalloc to avoid pyfakefs setup race - #43

Open
s0nea wants to merge 2 commits into
tentacle-20.2.4-cobaltcore-storagefrom
backport/627
Open

s0nea wants to merge 2 commits into
tentacle-20.2.4-cobaltcore-storagefrom
backport/627

Conversation

@s0nea

@s0nea s0nea commented Oct 26, 2026

Copy link
Copy Markdown

Closes cobaltcore-dev/cloud-storage#627

Backport file

  • release-management/backports/<uuid>.md added (or updated) by this PR
  • id in frontmatter matches the filename stem
  • provenance.upstream_prs set (or provenance.type: other with an other: block)

Stage-B risk (filled per release-management/backports/RISK-RUBRIC.md)

  • blast — cosmetic / availability / data-loss
  • conflict — clean / trivial / substantive
  • coverage — strong / partial / weak
  • Risk-notes paragraph in the prose section (required for high band)

Merge

Land this via just merge-backport PR=<N> — do not click the green merge button.
The just recipe constructs the merge commit's Backport-Id trailer.

djgalloway and others added 2 commits October 26, 2026 14:07
Since 2026-08-18 run_tox_cephadm has been failing in roughly a quarter of
arm64 make check runs (and ~8% of x86 runs) with

  RuntimeError: dictionary changed size during iteration
    pyfakefs/fake_filesystem_unittest.py:831 in Patcher._find_modules

during `fs` fixture setup, followed by 80+ cascading

  AttributeError: 'NoneType' object has no attribute 'add_real_directory'

because pyfakefs' Patcher is a ref-counted singleton and a failed setUp()
never gets its tearDown().

There is no second thread involved.  Several TestBootstrap tests run
command_bootstrap() to completion, which leaves NamedTemporaryFile objects
created on the fake filesystem to be garbage collected after the fake fs
has been torn down.  Their __del__ raises, which makes pytest's (>= 8.4)
unraisable-exception hook run *inside the GC pass*, and the first time it
does so it lazily imports tracemalloc (tracemalloc_message()).  If that GC
fires while pyfakefs 5.3.5 is doing `list(sys.modules.items())`, the
iteration blows up.  Newer pyfakefs (>= 5.10) snapshots sys.modules with
dict.copy() and is immune, but 5.10.x is not a drop-in upgrade for this
test suite, so import tracemalloc up front instead so that nothing new
gets added to sys.modules from within a finalizer.

Signed-off-by: David Galloway <david.galloway@ibm.com>
Assisted-by: Claude Fable 5 (claude-fable-5)
(cherry picked from commit 7989817)
(cherry picked from commit 44eff9c)
Signed-off-by: Tatjana Dehler <tatjana.dehler@clyso.com>
On-behalf-of: SAP <t.dehler@sap.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants