Skip to content

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

Open
djgalloway wants to merge 1 commit into
ceph:tentaclefrom
djgalloway:wip-cephadm-tox-tracemalloc-tentacle
Open

djgalloway wants to merge 1 commit into
ceph:tentaclefrom
djgalloway:wip-cephadm-tox-tracemalloc-tentacle

Conversation

@djgalloway

@djgalloway djgalloway commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #71163 (clean cherry-pick).

run_tox_cephadm fails intermittently (~25% of arm64 make check runs, ~8% x86 on main; tentacle uses the same pyfakefs 5.3.5 pin and unpinned pytest, so it is equally exposed) with RuntimeError: dictionary changed size during iteration in pyfakefs Patcher._find_modules followed by ~80 cascading 'NoneType' object has no attribute 'add_real_directory' errors. pytest ≥8.4's unraisable-exception hook lazily imports tracemalloc from inside a GC pass triggered by leaked NamedTemporaryFile finalizers; pre-importing it in conftest removes the sys.modules mutation.

backport tracker: https://tracker.ceph.com/issues/79677


  • this backport is a clean cherry-pick from main

@djgalloway
djgalloway requested a review from a team as a code owner August 20, 2026 14:24
@github-actions github-actions Bot added this to the tentacle milestone Aug 20, 2026
@djgalloway

Copy link
Copy Markdown
Contributor Author

/audit retest

@github-actions

Copy link
Copy Markdown

🔄 Audit Retest Triggered by @djgalloway.

View workflow run

@github-actions github-actions Bot added the releng-audit-pass Release engineering: passed backport verification audit. label Aug 20, 2026
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 <[email protected]>
Assisted-by: Claude Fable 5 (claude-fable-5)
(cherry picked from commit 7989817)
@djgalloway
djgalloway force-pushed the wip-cephadm-tox-tracemalloc-tentacle branch from 72d6c9b to 44eff9c Compare August 21, 2026 14:56
@github-actions github-actions Bot added releng-audit-pass Release engineering: passed backport verification audit. and removed releng-audit-pass Release engineering: passed backport verification audit. labels Aug 21, 2026
@djgalloway

Copy link
Copy Markdown
Contributor Author

jenkins test make check

s0nea added a commit to cobaltcore-dev/ceph that referenced this pull request Nov 3, 2026
…fakefs setup race (#43)

Backport-Id: 01a177f4-63f1-7e3d-a389-f72fcfbb888d
Backport-PR: #43
Upstream-PRs: ceph#71189, ceph#71163
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cephadm releng-audit-pass Release engineering: passed backport verification audit. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants