Skip to content

Fix pytest record contention issues due to non-atomic read-write - #2

Merged
ReeceStevens merged 1 commit into
mainfrom
fix-pytest-contention-issues
Sep 4, 2026
Merged

ReeceStevens merged 1 commit into
mainfrom
fix-pytest-contention-issues

Conversation

@ReeceStevens

Copy link
Copy Markdown
Member

We have been experiencing sporadic test failures on CI when xdist is enabled, especially for runners with > 2 cores (and thus multiple concurrent workers). There is a non-atomic write in the collected test record that is causing issues when multiple runners attempt to write to it simultaneously.

Every mutation must hold the lock across BOTH the read and the write. Reading
under one acquisition and writing under a second lets a concurrent writer slip
in between, and because each write serializes the whole mapping, that writer's
entries are silently dropped -- they are absent from the stale snapshot being
written back. Nothing ever re-adds them, so a later `update_test_status` for a
dropped node ID raises `KeyError`, which surfaces as an xdist INTERNALERROR
that aborts the entire session.
@ReeceStevens
ReeceStevens merged commit 0228cb3 into main Sep 4, 2026
6 checks passed
@ReeceStevens
ReeceStevens deleted the fix-pytest-contention-issues branch September 4, 2026 21:13
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.

1 participant