[PR #3614] [Other] Test: NoLeakedSampler loses a still-ending sampler between its two name counts (flaky 1 != 2) #4713

Open
opened 2026-11-07 15:38:32 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3614
Author: @victorgabr
Created: 10/21/2026
Status: 🔄 Open

Base: main ← Head: fix/leaked-sampler-baseline


📝 Commits (1)

  • 270c208 [Other] Test: NoLeakedSampler counted thread names before and after, but a sampler of a server a previous test closed keeps ending for up to a second, and losing that straggler between the two counts hid the one this server started (flaky 1 != 2, CI run 39625083194 among 929); count the new thread by identity instead and check it ends

📊 Changes

1 file changed (+10 additions, -4 deletions)

View changed files

📝 serve/test_responses.py (+10 -4)

📄 Description

Problem and result

serve/test_responses.py NoLeakedSampler.test_server_close_ends_the_sampler fails at random - once in 929 tests on CI (run 39625083194, step "Run full server suite without terminal packages") and about once in four plain python -m unittest serve.test_responses runs on Linux, always AssertionError: 1 != 2. After this change the module passes 8/8 on this machine.

Cause

The test counts threads named *(_loop) before and after serve() and expects before + 1. The name is not set on purpose: Python 3.10+ names an unnamed Thread after its target, and the telemetry sampler (serve/telemetry.py:584, target=self._loop) shows up as Thread-N (_loop). Telemetry.close() only sets _stop; the thread sits in _stop.wait(1.0) and ends up to a second after the close. A server closed by a test shortly before can still leave such a straggler: before counts it, it exits between the two counts, and the one thread this server started is hidden - 1 != 2. The name-total check cannot tell the two threads apart.

Approach

The test's own question - "one server, one sampler, and it ends with the server" - is answered by identity, not totals: record the set of sampler thread ids before, take the difference after serve() (a straggler leaving in between cannot affect the difference), and wait for that thread to end. Product behavior is unchanged: no close() or join changes, no sleeps added to the suite.

Validation

Passed (Linux, Python 3.10.9):

  • Before the fix: reproduced AssertionError: 1 != 2 locally (1 failure in 4 module runs).
  • After: 8/8 python -m unittest serve.test_responses OK, plus one more on the rebased branch.

Failed: none.

Not run: Windows and the 929-test suite locally (needs the engine build); the CI run will cover it.

Limits

The underlying one-second exit latency of the sampler is kept - it is the sample cadence, not a bug; only the test's counting is fixed.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/3614 **Author:** [@victorgabr](https://github.com/victorgabr) **Created:** 10/21/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/leaked-sampler-baseline` --- ### 📝 Commits (1) - [`270c208`](https://github.com/Niko1221/Strata/commit/270c208554762e2f3449e0cc27a4b8e0e3a307f2) [Other] Test: NoLeakedSampler counted thread names before and after, but a sampler of a server a previous test closed keeps ending for up to a second, and losing that straggler between the two counts hid the one this server started (flaky 1 != 2, CI run 39625083194 among 929); count the new thread by identity instead and check it ends ### 📊 Changes **1 file changed** (+10 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `serve/test_responses.py` (+10 -4) </details> ### 📄 Description ## Problem and result `serve/test_responses.py` `NoLeakedSampler.test_server_close_ends_the_sampler` fails at random - once in 929 tests on CI (run 39625083194, step "Run full server suite without terminal packages") and about once in four plain `python -m unittest serve.test_responses` runs on Linux, always `AssertionError: 1 != 2`. After this change the module passes 8/8 on this machine. ## Cause The test counts threads named `*(_loop)` before and after `serve()` and expects `before + 1`. The name is not set on purpose: Python 3.10+ names an unnamed `Thread` after its target, and the telemetry sampler (`serve/telemetry.py:584`, `target=self._loop`) shows up as `Thread-N (_loop)`. `Telemetry.close()` only sets `_stop`; the thread sits in `_stop.wait(1.0)` and ends up to a second after the close. A server closed by a test shortly before can still leave such a straggler: `before` counts it, it exits between the two counts, and the one thread this server started is hidden - `1 != 2`. The name-total check cannot tell the two threads apart. ## Approach The test's own question - "one server, one sampler, and it ends with the server" - is answered by identity, not totals: record the set of sampler thread ids before, take the difference after `serve()` (a straggler leaving in between cannot affect the difference), and wait for that thread to end. Product behavior is unchanged: no `close()` or join changes, no sleeps added to the suite. ## Validation **Passed** (Linux, Python 3.10.9): - Before the fix: reproduced `AssertionError: 1 != 2` locally (1 failure in 4 module runs). - After: 8/8 `python -m unittest serve.test_responses` OK, plus one more on the rebased branch. **Failed**: none. **Not run**: Windows and the 929-test suite locally (needs the engine build); the CI run will cover it. ## Limits The underlying one-second exit latency of the sampler is kept - it is the sample cadence, not a bug; only the test's counting is fixed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4713
No description provided.