Repository navigation
Fix the Windows engine stop and listen port bugs behind 0.7's CI flakes - #119
Merged
Merged
Conversation
Windows refuses a UDP port it reserves, as Hyper-V and WSL have it do, or one another account holds on every address, even where TCP binds the same port. libtorrent binds TCP first, then UDP on that port, and moves to another port only when a bind says the port is in use, so it listened nowhere on the address. This is how 18 engine tests and six swarm seeders failed on Windows CI during 0.7 work, with error 10013 on the uTP bind. The test finds such a port on the machine and asks a session for it.
A session now checks each listen address before libtorrent sees it, binding TCP and UDP there with the options libtorrent uses. Port 0, or a port either bind finds taken or refused, becomes one the OS offers for TCP where UDP binds too. On Windows that fixes an engine that listened nowhere when its saved listen port fell in a UDP range Windows reserves (a GitHub runner reserved 64202 to 64401 for UDP alone) or one another account held, and the test engines and seeders that failed on CI the same way. Without the change the new test fails on Windows with 10013 on the uTP bind; with it, it passes.
libtorrent 2.1 flushes a file to the disk after every write on Windows by default. On a GitHub Windows runner a 400 MiB loopback download wrote at 12.7 and 13.1 MiB/s that way, and pausing it took 3.5 s and 2.5 s while the queue drained; through the system cache, as on macOS and Linux, it wrote at 78.4 and 80.5 MiB/s and paused in 0.17 s and 0.12 s. With up to 100 MiB queued, a stop on a slower disk ran past the 10 s the engine waits for writes to stop and the 20 s engine stop waits for the exit, which is how the windows-install job's engine stop failed after Sintel downloaded fast. The windows-install job now says how long engine stop took and prints the engine log when it fails, and waits for the local release server to answer instead of sleeping 2 s, which once let install.ps1 ask before the server listened.
The play tests that pin the release that sends its file list gave it the 500 ms the other tests use to give up on a dead swarm quickly. On a busy Windows runner the file list took longer, and the test that checks a play never writes into the person's own folder of the same name failed before it checked anything. Those tests now give each wait the play's whole budget, so they wait as long as the file list and first bytes take and no longer.
The test failed once on Windows with exit code 6 from its first get and no message. It now prints the command's stderr, how long it took, and the engine log, so the next failure says whether the engine did not start in time or was refused.
Owner
Author
|
CI run 44094900135 ran four times: the first run and three full re-runs with
Before this PR, the same stop failed after 30 s, with 110 MB of Sintel verified. Attempt 3 had one failure off Windows. The macOS test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four Windows CI failures happened once each during 0.7 work and passed on rerun. Two were real bugs that people on Windows would hit, one was a test that waited wrongly, and one did not reproduce.
Engine stop took over 30 s (windows-install). Real bug. libtorrent 2.1 flushes a file to the disk after every write on Windows by default (
write_through). A download then goes only as fast as the disk takes those flushes, and a pause or stop waits while up to 100 MiB of queued writes go out that way. On a GitHub Windows runner, a 400 MiB loopback download wrote at 12.7 and 13.1 MiB/s and paused in 3.5 s and 2.5 s. Through the system cache it wrote at 78.4 and 80.5 MiB/s and paused in 0.17 s and 0.12 s. In the failed run Sintel had 110 MB verified 5 s afterget. The stop spent the engine's full 10 s waiting for writes, then the CLI's 20 s waiting for the exit. The engine now writes through the system cache on every platform. The windows-install job, which caught this, now prints how longengine stoptook and the engine log when it fails. It also waits for its local release server to answer instead of sleeping 2 s, which once failed the 0.6.0 release run.Six swarm tests: "the seeder never verified its files". Real bug. The seeder never got a listen port. libtorrent binds TCP on a port, then UDP on the same port, and moves on only when a bind says the port is in use. Windows refuses a UDP port it reserves, or one another account holds, with WSAEACCES (10013), even where TCP binds. libtorrent then listened nowhere on that address. A runner listed UDP 64202 to 64401 as reserved, a range TCP could still use, and 2 of 2000 TCP ports refused UDP. The hotfix-0.6.1 run had 18 engine tests fail with this exact error. A real engine has the same exposure: its saved listen port could fall in such a range, leaving no incoming peers, no uTP and no DHT.
Session::newnow checks each listen address with libtorrent's socket options and takes an OS-offered port where TCP and UDP both bind. The new test finds a port Windows refuses for UDP and asks a session for it. It fails on Windows without the fix (10013 on the uTP bind, run 44091598981) and passes with it.a_title_play_downloads_into_a_folder_of_its_own…. The test waited wrongly but checks something real. It pins the release that answers but gave it the 500 ms file-list wait the other tests use to give up on a dead swarm. On a busy runner the file list came later, and the test failed before it checked anything. The tests that pin that release now give each wait the play's whole budget, so they end as soon as the file list and first bytes arrive. The check that a play never writes into the person's own folder of the same name is unchanged.a_killed_engine_comes_back_with_the_download_running. The cause is unknown. Its firstgetexited 6 (engine or environment) and the test printed no message. Eight runs of all 36 process tests on a Windows runner passed. The failure was in starting the engine, which every process test does, not in what this test checks, so deleting it would remove no flake. It now prints the command's stderr, the time it took, and the engine log, so a next failure says why.The Windows CI job is re-run at least three times on this PR. The results are in the comments.
🤖 Generated with Claude Code