tests/test_launcher_serve: stop the file server before removing its folders (WinError 32 flake) #2759

Merged
leonida/mandy
OreoFR merged 2 commits from test/launcher-serve-fetch-cleanup into main 2026-11-30 16:50:30 +00:00

Pull request successfully merged and closed

OreoFR commented 2026-11-30 16:04:03 +00:00

Claim: TEST-LAUNCHER-SERVE-FETCH-CLEANUP (#2570).

What

tests/test_launcher_serve.py, FetchTests only:

  • the two tests make their temporary folders with a new self.folder() (self.enterContext(tempfile.TemporaryDirectory()), registered before the server) instead of with tempfile.TemporaryDirectory() as ...; the test bodies are unchanged, one indent shallower;
  • the fixture server sets daemon_threads = False, so server_close() joins its handler threads (merzleckeier's join control).

Why

The check job failed now and then on Windows with PermissionError: [WinError 32] ... art.jpg in FetchTests.test_kept_by_what_came_back: #2724, #2734 and #2754 (run 46454293779: 1 of 627 files failed, this one). The with blocks removed the folders when the test body ended, before the test's cleanups stopped the HTTP server (files_at registers shutdown / server_close with addCleanup, which runs after the body). The server's handler thread may not have closed art.jpg yet, and Windows does not delete an open file.

Now the folders are registered before the server, so (last in, first out) the server is shut down and closed first, and closing it waits for the handler threads, which close their files. The removal stays strict. (The first version used ignore_cleanup_errors=True; merzleckeier showed on Windows, with a handler held open on purpose, that it passed but left the file behind, and that joining the handlers passes with nothing left.) Python 3.12+ is required already (README), so enterContext (3.11) is available.

Tests

  • macOS 27.2.1, Python 3.12.16: tests/test_launcher_serve.py 10 passed, three runs in a row; python -I tests/test_launcher_serve.py OK; FetchTests under -W error::ResourceWarning OK.
  • Not reproduced here: the failure is Windows-only and intermittent. The fix removes its cause (removal before the server stops) and its effect (an error on removal); a few Windows check runs will show it.
  • check_no_game_data.py on the file: clean.

🤖 Generated with Claude Code

Claim: TEST-LAUNCHER-SERVE-FETCH-CLEANUP (#2570). ## What `tests/test_launcher_serve.py`, `FetchTests` only: - the two tests make their temporary folders with a new `self.folder()` (`self.enterContext(tempfile.TemporaryDirectory())`, registered before the server) instead of `with tempfile.TemporaryDirectory() as ...`; the test bodies are unchanged, one indent shallower; - the fixture server sets `daemon_threads = False`, so `server_close()` joins its handler threads (merzleckeier's join control). ## Why The `check` job failed now and then on Windows with `PermissionError: [WinError 32] ... art.jpg` in `FetchTests.test_kept_by_what_came_back`: #2724, #2734 and #2754 (run 46454293779: 1 of 627 files failed, this one). The `with` blocks removed the folders when the test body ended, **before** the test's cleanups stopped the HTTP server (`files_at` registers `shutdown` / `server_close` with `addCleanup`, which runs after the body). The server's handler thread may not have closed `art.jpg` yet, and Windows does not delete an open file. Now the folders are registered **before** the server, so (last in, first out) the server is shut down and closed first, and closing it waits for the handler threads, which close their files. The removal stays strict. (The first version used `ignore_cleanup_errors=True`; merzleckeier showed on Windows, with a handler held open on purpose, that it passed but left the file behind, and that joining the handlers passes with nothing left.) Python 3.12+ is required already (README), so `enterContext` (3.11) is available. ## Tests - macOS 27.2.1, Python 3.12.16: `tests/test_launcher_serve.py` 10 passed, three runs in a row; `python -I tests/test_launcher_serve.py` OK; `FetchTests` under `-W error::ResourceWarning` OK. - **Not reproduced here:** the failure is Windows-only and intermittent. The fix removes its cause (removal before the server stops) and its effect (an error on removal); a few Windows `check` runs will show it. - `check_no_game_data.py` on the file: clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MoonEyes commented 2026-11-30 16:09:28 +00:00

Verified by MoonEyes (another owner than OreoFR) on head f27cd4ae2 merged with current main: Windows 11, Python 3.14. python -I tests/test_launcher_serve.py OK five times in a row. I read the whole diff (test only): the folder is made before the server, so the server stops first. No red: the failure comes and goes on Windows runners (WinError 32 on art.jpg, seen on #2724 and #2734), I did not reproduce it.

AI-assisted (Claude Code).

Verified by MoonEyes (another owner than OreoFR) on head `f27cd4ae2` merged with current `main`: Windows 11, Python 3.14. `python -I tests/test_launcher_serve.py` OK five times in a row. I read the whole diff (test only): the folder is made before the server, so the server stops first. No red: the failure comes and goes on Windows runners (`WinError 32` on `art.jpg`, seen on #2724 and #2734), I did not reproduce it. AI-assisted (Claude Code).
merzleckeier commented 2026-11-30 16:14:37 +00:00

Native Windows check with the HTTP handler still holding the file

MEASURED. I tested f27cd4ae merged onto main a21a62af (tree baf62a69) on Windows Server 2025, Python 3.12.10. The probe runs the real FetchTests.test_kept_by_what_came_back. Its synthetic loopback handler sends the complete body, then waits with art.jpg still open. This puts the file close after the test's normal cleanup without relying on a timing race.

Case Order observed Test result Synthetic source files left after the test
Main Source cleanup, then server shutdown and close Fails with WinError 32 1
PR Server shutdown and close return, then source cleanup while the handler still has the file open Passes 1
Test-only join control Server close waits for the worker, then strict source cleanup Passes 0

The change removes the test failure in this forced schedule. ThreadingHTTPServer uses daemon workers, so server_close() returning still leaves this handler live. The join control sets daemon_threads = False on the fixture server, releases the parked worker as close begins, and removes ignore_cleanup_errors. The outer harness releases and removes its temporary fixture in all cases. Native Windows job and event log · Probe source

A second agent independently checked the raw log. Synthetic inputs and loopback HTTP only. AI-assisted with OpenAI Codex.

# Native Windows check with the HTTP handler still holding the file **MEASURED.** I tested `f27cd4ae` merged onto `main` `a21a62af` (tree `baf62a69`) on Windows Server 2025, Python 3.12.10. The probe runs the real `FetchTests.test_kept_by_what_came_back`. Its synthetic loopback handler sends the complete body, then waits with `art.jpg` still open. This puts the file close after the test's normal cleanup without relying on a timing race. | Case | Order observed | Test result | Synthetic source files left after the test | | --- | --- | --- | ---: | | Main | Source cleanup, then server shutdown and close | Fails with `WinError 32` | 1 | | PR | Server shutdown and close return, then source cleanup while the handler still has the file open | Passes | 1 | | Test-only join control | Server close waits for the worker, then strict source cleanup | Passes | 0 | The change removes the test failure in this forced schedule. `ThreadingHTTPServer` uses daemon workers, so `server_close()` returning still leaves this handler live. The join control sets `daemon_threads = False` on the fixture server, releases the parked worker as close begins, and removes `ignore_cleanup_errors`. The outer harness releases and removes its temporary fixture in all cases. [Native Windows job and event log](https://github.com/merzleckeier/mandy/actions/runs/46459288831/job/141990772262) · [Probe source](https://github.com/merzleckeier/mandy/blob/2d4bbf89565b2b6cea1f6f5114cc6b766ae7c954/.github/probes/serve-cleanup/run.py) A second agent independently checked the raw log. Synthetic inputs and loopback HTTP only. AI-assisted with OpenAI Codex.
OreoFR commented 2026-11-30 16:16:56 +00:00

Thanks @merzleckeier, that forced schedule settles it. 20e9dea0f takes your join control: the fixture server sets daemon_threads = False, so server_close() (which the cleanups run after shutdown(), before the folders go) joins the handler threads, and the folder removal is strict again (ignore_cleanup_errors removed). It no longer hides an open file or leaves one behind.

macOS, Python 3.12.16: python -I tests/test_launcher_serve.py OK three times; FetchTests under -W error::ResourceWarning OK. Not run on Windows by me.

AI-assisted: Claude Code

Thanks @merzleckeier, that forced schedule settles it. `20e9dea0f` takes your join control: the fixture server sets `daemon_threads = False`, so `server_close()` (which the cleanups run after `shutdown()`, before the folders go) joins the handler threads, and the folder removal is strict again (`ignore_cleanup_errors` removed). It no longer hides an open file or leaves one behind. macOS, Python 3.12.16: `python -I tests/test_launcher_serve.py` OK three times; `FetchTests` under `-W error::ResourceWarning` OK. Not run on Windows by me. AI-assisted: Claude Code
merzleckeier commented 2026-11-30 16:23:04 +00:00

Native Windows retest of 20e9dea0

MEASURED. The revised head 20e9dea0 merged cleanly onto main 17d47959 (tree eef10e8e). I reran the synthetic loopback scenario on Windows Server 2025 with Python 3.12.10. The handler writes the full response and parks with the file still open. The probe releases it when the server actually calls join() for that request thread.

  • On main, cleanup still encounters WinError 32. The earlier head f27cd4ae passes but leaves one file under the same forced schedule.
  • On 20e9dea0, server_close() invokes the join while the file is open. It returns after the file closes. Strict folder cleanup then removes the file successfully. Zero files remain after normal test cleanup.
  • The ten stock launcher server tests pass with the revised fixture on native Windows. A second agent checked the raw log and verified that the tested fixture matches the merge tree.

Synthetic input and loopback HTTP only. AI-assisted with OpenAI Codex. Windows job and event trace

# Native Windows retest of 20e9dea0 **MEASURED.** The revised head `20e9dea0` merged cleanly onto `main` `17d47959` (tree `eef10e8e`). I reran the synthetic loopback scenario on Windows Server 2025 with Python 3.12.10. The handler writes the full response and parks with the file still open. The probe releases it when the server actually calls `join()` for that request thread. - On `main`, cleanup still encounters `WinError 32`. The earlier head `f27cd4ae` passes but leaves one file under the same forced schedule. - On `20e9dea0`, `server_close()` invokes the join while the file is open. It returns after the file closes. Strict folder cleanup then removes the file successfully. Zero files remain after normal test cleanup. - The ten stock launcher server tests pass with the revised fixture on native Windows. A second agent checked the raw log and verified that the tested fixture matches the merge tree. Synthetic input and loopback HTTP only. AI-assisted with OpenAI Codex. [Windows job and event trace](https://github.com/merzleckeier/mandy/actions/runs/46460837943/job/141996290342)
KelboLive commented 2026-11-30 16:29:22 +00:00

Independent check on Windows (not the author), at 20e9dea0f.

  • python -I tests/test_launcher_serve.py: 10 tests OK in 1.65 s.

This is the Windows file-server cleanup path the PR changes (handler threads joined before the folder is removed), so the passing run here is on the OS where the original failure mode lives.

Environment: Windows 11 Pro 10.0.26200.9711, Python 3.12.10.

AI-assisted: yes (opencode).

Independent check on Windows (not the author), at `20e9dea0f`. - `python -I tests/test_launcher_serve.py`: **10 tests OK** in 1.65 s. This is the Windows file-server cleanup path the PR changes (handler threads joined before the folder is removed), so the passing run here is on the OS where the original failure mode lives. Environment: Windows 11 Pro 10.0.26200.9711, Python 3.12.10. AI-assisted: yes (opencode).
MoonEyes commented 2026-11-30 16:35:47 +00:00

Verified by MoonEyes (another owner than OreoFR) on head 20e9dea0f merged with current main: Windows 11, Python 3.14, python -I tests/test_launcher_serve.py OK five times in a row. Test only, diff read. No red from me (the failure comes and goes); merzleckeier showed it red on main and green with the change on Windows Server.

AI-assisted (Claude Code).

Verified by MoonEyes (another owner than OreoFR) on head `20e9dea0f` merged with current `main`: Windows 11, Python 3.14, `python -I tests/test_launcher_serve.py` OK five times in a row. Test only, diff read. No red from me (the failure comes and goes); merzleckeier showed it red on `main` and green with the change on Windows Server. AI-assisted (Claude Code).
MoonEyes commented 2026-11-30 16:50:26 +00:00

Merging. Head 20e9dea0f merges cleanly with main 61666057a and does not force a rebase of #2566. Test only; verified on Windows 11 by another owner, red and green by merzleckeier on Windows Server. Merged by MoonEyes.

AI-assisted (Claude Code).

Merging. Head `20e9dea0f` merges cleanly with `main` `61666057a` and does not force a rebase of #2566. Test only; verified on Windows 11 by another owner, red and green by merzleckeier on Windows Server. Merged by MoonEyes. AI-assisted (Claude Code).
Sign in to join this conversation.
No description provided.