Repository navigation
fix: make port allocation conflict-safe and overflow-free - #245
Closed
OzzyHelper wants to merge 1 commit into
Closed
OzzyHelper wants to merge 1 commit into
OzzyHelper wants to merge 1 commit into
Conversation
- PortAllocator stores the inclusive end port instead of a count, so no code path computes start + count (which overflowed u16 for ranges ending at 65535 and panicked in debug builds). - allocate() now probes the host and skips ports that are already bound, instead of handing out ports another process owns. - is_port_available probes the wildcard address Docker binds and treats port 0 as unavailable. - Range setup is one shared helper; the parallel executor no longer fails when the Portainer port is outside the configured range. - Config::validate rejects empty, port-0, and overflowing ranges. - Curio re-checks its published ports right before container create.
Collaborator
|
not worth it |
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.
What
Port allocation is now conflict-safe and free of u16 range-validation overflow.
Why
Two failure modes in the startup port pool:
PortAllocatorstored acountand every consumer computedstart + count. For a valid range ending at 65535 (e.g. 65000 + 536), that addition overflowsu16— a panic in debug builds and a wrapped value that turnsallocate()into an infinite/incorrect loop in release builds. Config never rejected such ranges either.allocate()only checked its own set; a port taken by another process after the initial pre-flight check was silently handed to a container, which then failed to start with a Docker port-binding error.How
PortAllocatorstores the inclusiveendport, sostart + countis never computed.new()rejectscount == 0,start == 0, and overflow.allocate()probes the host and skips (reserving) ports that are already bound; the exhaustion error lists which ports were busy.is_port_availableprobes0.0.0.0(what Docker publishes on) as well as loopback, and reports port 0 unavailable.build_port_allocatorhelper replaces the duplicated (and divergent) range checks in the sequential and parallel executors. This also fixes the parallel path erroring out when the Portainer port fell outside the range.Config::validatereuses the allocator constructor to reject invalid ranges early.docker create, since they are allocated minutes earlier in pre-execute.Testing
cargo test --lib: 60 passed; the 2 failures (test_print_running_status,test_print_uptime) are pre-existing and need a Docker CLI.cargo clippy --all-targets -- -D warningsandcargo fmt --checkclean.Quality Report
Changes: 7 files changed, 282 insertions(+), 146 deletions(-)
Code scan: clean
Tests: skipped
Branch hygiene: 1 issue(s)