[GH-ISSUE #5270] [Benchmark] Windows: a real timeout can be classified connection_TimeoutError (timer thread races the socket timeout) #3138

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

Originally created by @yeyeyeason on GitHub (Nov 5, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/5270

Area

[Benchmark] (measurements and reports)

Desktop app, Terminal or source?

Source (START-HERE.bat, setup.sh or a build)

What happened

tests/terminal/test_bench_standard.py::RunTests::test_a_request_that_never_finishes_times_out intermittently fails on Windows with:

AssertionError: Tuples differ: ('failed', 'connection_TimeoutError') != ('failed', 'timeout')

It failed once and passed once in two consecutive full-file runs — intermittent, consistent with a race.

stream_chat (strata_cli/bench_standard.py:181-303) enforces its timeout with two mechanisms racing each other: the socket's own timeout (an HTTPConnection(timeout_s) raising TimeoutError from readline()) and a threading.Timer (bench_standard.py:193-207) whose expire() sets raw["timed_out"] = True and then closes the socket. The handler at bench_standard.py:289-293 classifies by the flag first, so when the socket timeout raises a few milliseconds before the timer thread runs its assignment, a genuine timeout is labeled connection_TimeoutError.

A stdlib-only minimal reproduction of the pattern (one hanging server, the same timer-plus-flag-and-close, 0.6 s on both paths) misclassified 1 run in 5:

exception: TimeoutError | timed_out = True   -> "timeout"          (4 of 5)
exception: TimeoutError | timed_out = False  -> "connection_..."   (1 of 5)

Windows timer-thread scheduling makes this window easy to hit; on Linux it is narrower.

A one-line fix covers it: in the except handler, treat a TimeoutError/socket.timeout itself as a timeout in addition to the flag, e.g.

if raw["timed_out"] or isinstance(exc, (TimeoutError, socket.timeout)):

Happy to prepare the PR if agreed.

Smallest steps or command that reproduce it

From a v0.2.10 checkout on Windows:

.venv\Scripts\python.exe -m pytest tests/terminal/test_bench_standard.py -q

Intermittent: failed once, passed once in two consecutive runs. The minimal reproduction reproduces the misclassification itself 1-in-5.

Reproduction status

Reproduced locally

Strata version

v0.2.10 checkout, commit ffa80d73

Graphics card, memory and system

RTX 4060 Ti 16 GB x2 · 96 GB RAM · Windows 11 Pro (no GPU is used by these tests)

Model, size and settings

Not applicable — mock-server test path.

Logs

The two failing assertions and the minimal reproduction output are quoted above; the repro script is ~40 lines of stdlib only and can be attached if useful.

Originally created by @yeyeyeason on GitHub (Nov 5, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/5270 ### Area [Benchmark] (measurements and reports) ### Desktop app, Terminal or source? Source (START-HERE.bat, setup.sh or a build) ### What happened `tests/terminal/test_bench_standard.py::RunTests::test_a_request_that_never_finishes_times_out` intermittently fails on Windows with: ``` AssertionError: Tuples differ: ('failed', 'connection_TimeoutError') != ('failed', 'timeout') ``` It failed once and passed once in two consecutive full-file runs — intermittent, consistent with a race. `stream_chat` (`strata_cli/bench_standard.py:181-303`) enforces its timeout with two mechanisms racing each other: the socket's own timeout (an `HTTPConnection(timeout_s)` raising `TimeoutError` from `readline()`) and a `threading.Timer` (`bench_standard.py:193-207`) whose `expire()` sets `raw["timed_out"] = True` and then closes the socket. The handler at `bench_standard.py:289-293` classifies by the flag first, so when the socket timeout raises a few milliseconds before the timer thread runs its assignment, a genuine timeout is labeled `connection_TimeoutError`. A stdlib-only minimal reproduction of the pattern (one hanging server, the same timer-plus-flag-and-close, 0.6 s on both paths) misclassified 1 run in 5: ``` exception: TimeoutError | timed_out = True -> "timeout" (4 of 5) exception: TimeoutError | timed_out = False -> "connection_..." (1 of 5) ``` Windows timer-thread scheduling makes this window easy to hit; on Linux it is narrower. A one-line fix covers it: in the `except` handler, treat a `TimeoutError`/`socket.timeout` itself as a timeout in addition to the flag, e.g. ```python if raw["timed_out"] or isinstance(exc, (TimeoutError, socket.timeout)): ``` Happy to prepare the PR if agreed. ### Smallest steps or command that reproduce it From a v0.2.10 checkout on Windows: ``` .venv\Scripts\python.exe -m pytest tests/terminal/test_bench_standard.py -q ``` Intermittent: failed once, passed once in two consecutive runs. The minimal reproduction reproduces the misclassification itself 1-in-5. ### Reproduction status Reproduced locally ### Strata version v0.2.10 checkout, commit ffa80d73 ### Graphics card, memory and system RTX 4060 Ti 16 GB x2 · 96 GB RAM · Windows 11 Pro (no GPU is used by these tests) ### Model, size and settings Not applicable — mock-server test path. ### Logs The two failing assertions and the minimal reproduction output are quoted above; the repro script is ~40 lines of stdlib only and can be attached if useful.
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#3138
No description provided.