Skip to content

make the thread-leak test wait on the thing it asserts - #63

Merged
hyj28 merged 1 commit into
mainfrom
mcp-thread-count-race
Sep 26, 2026
Merged

hyj28 merged 1 commit into
mainfrom
mcp-thread-count-race

Conversation

@hyj28

@hyj28 hyj28 commented Sep 26, 2026

Copy link
Copy Markdown
Owner

Linux CI went red on main with assert 3 == 2 at test_nonresponding_server_timeout_leaves_no_client_work, having passed on macOS and on the same commit's PR run. A re-run of that job came back green, so it is a race rather than a regression.

The test waited on one observable and asserted another

The loop polled server.active_handlers to zero — but the handler decrements that counter from inside itself and then still has to unwind and exit. So there is a window where the counter reads zero while the thread object is still alive, and threading.active_count() was read inside it.

That is this repository's recurring defect shape in a new place: the quantity waited on is not the quantity asserted.

-                if active == 0:
+                if active == 0 and threading.active_count() == before_threads:

Nothing is skipped or softened. If the thread count does not return to baseline within the existing 50 × 0.01s bound, the assertion still fails.

The old record is kept, not closed

CONTRIBUTING.md carried a note about an unidentified intermittent failure at 817b96d (1 failed, 1259 passed, six clean retries, name never captured). It is tempting to close that against this entry, and the file now explicitly declines to: the name was never recorded, so whether the two are the same incident is unknown. Both are recorded, separately, as what they are.

Gates

pytest 1286 passed, 3 skipped, unchanged — this repairs an existing test rather than adding behaviour. ruff check . and ruff format --check . exit 0. One assertion-line change plus the documentation entry; no assertion deleted, skipped or loosened.

The race is Linux-specific, so local stress is weak evidence: 25/25 green on macOS, where it already passed. CI on this PR is the real check.

Linux CI went red on main with `assert 3 == 2` at
test_nonresponding_server_timeout_leaves_no_client_work, having passed on macOS
and on the same commit's pull-request run. A re-run was green, so it is a race.

The test waited on one observable and asserted another. Its loop polled the
server's active-handler count to zero, but the handler decrements that counter
from inside itself and then still has to unwind, so there is a window where the
counter reads zero while the thread object is alive. thread_count was therefore
read before the quantity it measures had settled.

The wait now polls the thread count alongside the handler count, inside the same
bound. Nothing is skipped or softened: if the count does not return to baseline
within the existing 50 x 0.01s window the assertion still fails.

CONTRIBUTING.md carried a record of an unidentified intermittent failure at
817b96d. This entry does not close it. The earlier failure's name was never
captured, so whether the two are the same incident is unknown, and this file
does not round "not reproduced" into "does not exist" -- both are now recorded,
separately and as what they are.
@hyj28
hyj28 merged commit 4fbe957 into main Sep 26, 2026
2 checks passed
@hyj28
hyj28 deleted the mcp-thread-count-race branch September 26, 2026 07:51
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