fix(expose): skip Windows/Hyper-V excluded port ranges on WSL2 - #122
Merged
Conversation
On WSL2 + Docker Desktop, Windows and Hyper-V dynamically reserve TCP port ranges (netsh excludedportrange), and those ranges move on every Windows reboot. The host-port allocator only bind-tested inside the Linux distro, which cannot see the Windows-side reservation, so it would hand out a port (e.g. minio's 59000) that Docker Desktop's Windows-side forward then rejects with: ports are not available: exposing port TCP 127.0.0.1:59000 -> 127.0.0.1:0: /forwards/expose returned unexpected status: 500 FreeHostPort now queries netsh.exe on WSL2, treats excluded ranges as unavailable during allocation, and releases a persisted port that has fallen into a newly-excluded range so it re-allocates a usable one. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
On WSL2 + Docker Desktop, Windows and Hyper-V dynamically reserve TCP port ranges (netsh excludedportrange), and those ranges move on every Windows reboot. The host-port allocator only bind-tested inside the Linux distro, which cannot see the Windows-side reservation, so it would hand out a port (e.g. minio's 59000) that Docker Desktop's Windows-side forward then rejects with:
ports are not available: exposing port TCP 127.0.0.1:59000 ->
127.0.0.1:0: /forwards/expose returned unexpected status: 500
FreeHostPort now queries netsh.exe on WSL2, treats excluded ranges as unavailable during allocation, and releases a persisted port that has fallen into a newly-excluded range so it re-allocates a usable one.