tests/test_launcher_serve: stop the file server before removing its folders (WinError 32 flake) #2759
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2759
Loading…
Reference in a new issue
No description provided.
Delete branch "test/launcher-serve-fetch-cleanup"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Claim: TEST-LAUNCHER-SERVE-FETCH-CLEANUP (#2570).
What
tests/test_launcher_serve.py,FetchTestsonly:self.folder()(self.enterContext(tempfile.TemporaryDirectory()), registered before the server) instead ofwith tempfile.TemporaryDirectory() as ...; the test bodies are unchanged, one indent shallower;daemon_threads = False, soserver_close()joins its handler threads (merzleckeier's join control).Why
The
checkjob failed now and then on Windows withPermissionError: [WinError 32] ... art.jpginFetchTests.test_kept_by_what_came_back: #2724, #2734 and #2754 (run 46454293779: 1 of 627 files failed, this one). Thewithblocks removed the folders when the test body ended, before the test's cleanups stopped the HTTP server (files_atregistersshutdown/server_closewithaddCleanup, which runs after the body). The server's handler thread may not have closedart.jpgyet, 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), soenterContext(3.11) is available.Tests
tests/test_launcher_serve.py10 passed, three runs in a row;python -I tests/test_launcher_serve.pyOK;FetchTestsunder-W error::ResourceWarningOK.checkruns will show it.check_no_game_data.pyon the file: clean.🤖 Generated with Claude Code
Verified by MoonEyes (another owner than OreoFR) on head
f27cd4ae2merged with currentmain: Windows 11, Python 3.14.python -I tests/test_launcher_serve.pyOK 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 32onart.jpg, seen on #2724 and #2734), I did not reproduce it.AI-assisted (Claude Code).
Native Windows check with the HTTP handler still holding the file
MEASURED. I tested
f27cd4aemerged ontomaina21a62af(treebaf62a69) on Windows Server 2025, Python 3.12.10. The probe runs the realFetchTests.test_kept_by_what_came_back. Its synthetic loopback handler sends the complete body, then waits withart.jpgstill open. This puts the file close after the test's normal cleanup without relying on a timing race.WinError 32The change removes the test failure in this forced schedule.
ThreadingHTTPServeruses daemon workers, soserver_close()returning still leaves this handler live. The join control setsdaemon_threads = Falseon the fixture server, releases the parked worker as close begins, and removesignore_cleanup_errors. The outer harness releases and removes its temporary fixture in all cases. Native Windows job and event log · Probe sourceA second agent independently checked the raw log. Synthetic inputs and loopback HTTP only. AI-assisted with OpenAI Codex.
Thanks @merzleckeier, that forced schedule settles it.
20e9dea0ftakes your join control: the fixture server setsdaemon_threads = False, soserver_close()(which the cleanups run aftershutdown(), before the folders go) joins the handler threads, and the folder removal is strict again (ignore_cleanup_errorsremoved). It no longer hides an open file or leaves one behind.macOS, Python 3.12.16:
python -I tests/test_launcher_serve.pyOK three times;FetchTestsunder-W error::ResourceWarningOK. Not run on Windows by me.AI-assisted: Claude Code
Native Windows retest of 20e9dea0
MEASURED. The revised head
20e9dea0merged cleanly ontomain17d47959(treeeef10e8e). 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 callsjoin()for that request thread.main, cleanup still encountersWinError 32. The earlier headf27cd4aepasses but leaves one file under the same forced schedule.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.Synthetic input and loopback HTTP only. AI-assisted with OpenAI Codex. Windows job and event trace
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).
Verified by MoonEyes (another owner than OreoFR) on head
20e9dea0fmerged with currentmain: Windows 11, Python 3.14,python -I tests/test_launcher_serve.pyOK five times in a row. Test only, diff read. No red from me (the failure comes and goes); merzleckeier showed it red onmainand green with the change on Windows Server.AI-assisted (Claude Code).
Merging. Head
20e9dea0fmerges cleanly withmain61666057aand 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).