Skip to content

api/types/network: fix handling of unmapped ports (ephemeral ports)#52288

Merged
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:fix_ephemeral_ports
Apr 2, 2026
Merged

api/types/network: fix handling of unmapped ports (ephemeral ports)#52288
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:fix_ephemeral_ports

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

commit 4c24542 changed PortRange.All() to omit zero values for ports, but this caused a regression; the zero-value is used in some places to assign an ephemeral port, e.g.: --port 80 is an implicit --port 0:80, or --port <ephemeral port>:80, where the daemon picks a random port number from the ephemeral port range as host-port.

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes

- A picture of a cute animal (not mandatory but encouraged)

commit 4c24542 changed `PortRange.All()`
to omit zero values for ports, but this caused a regression; the zero-value
is used in some places to assign an ephemeral port, e.g.: `--port 80` is an
implicit `--port 0:80`, or `--port <ephemeral port>:80`, where the daemon
picks a random port number from the ephemeral port range as host-port.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Comment on lines -281 to +282
assert.Check(t, slices.Equal(slices.Collect(pr.All()), []network.Port{}))
var ephemeralPort network.Port
assert.Check(t, slices.Equal(slices.Collect(pr.All()), []network.Port{ephemeralPort}))
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW; I think we should look if we can just make this work; this fix means that an empty port-range requires at least 1 zero-value in it? Perhaps we could/should ultimately also make it work with an empty slice, but I need to look at the CLI side (which discarded the range if it's empty), so for now this seems like the safest bet.

@thaJeztah thaJeztah merged commit 24aa57d into moby:master Apr 2, 2026
215 of 216 checks passed
@thaJeztah thaJeztah deleted the fix_ephemeral_ports branch April 2, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants