Files
dotfiles/overlays/patches/sentry-sdk/README.md
T
Richie 50d4aa383f
treefmt / nix fmt (pull_request) Successful in 3s
test ebook search / test-ebook-search (pull_request) Failing after 8h50m21s
pytest / pytest (pull_request) Failing after 8h50m22s
build_systems / build-rhapsody-in-green (pull_request) Failing after 8h50m23s
build_systems / build-portal-1 (pull_request) Failing after 8h50m24s
build_systems / build-jeeves (pull_request) Failing after 8h50m24s
build_systems / build-brain (pull_request) Failing after 8h50m24s
build_systems / build-bob (pull_request) Failing after 8h50m24s
Clean up overlays and remove obsolete dependencies
2026-09-18 19:59:12 -04:00

2.4 KiB

Sentry SDK thread-metadata test isolation

The fallback tests globally mock threading.current_thread while a worker is running. Python 3.14's Thread.join() also calls that function. A one-use mock can therefore be consumed by the wrong caller or raise StopIteration when the main thread joins the worker.

Scope and behavior

isolate-threading-mocks.patch changes three neighboring thread-metadata tests in tests/test_utils.py, including the formerly excluded test_get_current_thread_meta_main_thread.

Each test replaces only sentry_sdk.utils.threading, wraps the real module for unmocked operations, and sets the SDK lookup's return value. The real Thread.join() continues using Python's unmodified threading module. The fallback-result assertions remain; SDK production code is unchanged.

Reproduction and focused checks

Use a disposable Sentry SDK 2.66.0 checkout and its Python test dependencies. From this directory:

patch --fuzz=0 -d /path/to/sentry-python -p1 < isolate-threading-mocks.patch
cd /path/to/sentry-python
python -m pytest tests/test_utils.py -k get_current_thread_meta -q

To reproduce the race, hold the worker inside its mock just after get_current_thread_meta() returns, signal that point to the main thread, and call Thread.join() before releasing the worker. Use an independent bounded release so the patched join can finish. The original test raises StopIteration in join; the patched test passes under the same schedule. Perform this scheduling instrumentation only in a disposable checkout.

Upstream status

This is a standalone test patch for Sentry SDK 2.66.0. No upstream submission was made during this work. Recheck mock isolation and Python threading behavior when upgrading the SDK or interpreter.

Local NixOS integration and build results

../default.nix loads default.nix through pythonPackagesExtensions. From the repository root:

nix build --no-link -L .#nixosConfigurations.jeeves.pkgs.python314Packages.sentry-sdk

The patched package passed 2,356 tests with 116 existing skips on Python 3.14.7. The controlled join reproduction failed before the fix and passed after it.

That package build used the preceding dependency set with this patch to avoid unrelated rebuilds after pytest-xdist changed. The integrated host derivation was evaluated; a complete NixOS rebuild was not performed.