Skip to content

api/types/network: Port,PortRange: don't panic on zero values, add Port.Port()#52165

Merged
thaJeztah merged 4 commits intomoby:masterfrom
thaJeztah:network_portfixes
Mar 14, 2026
Merged

api/types/network: Port,PortRange: don't panic on zero values, add Port.Port()#52165
thaJeztah merged 4 commits intomoby:masterfrom
thaJeztah:network_portfixes

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

api/types/network: Port,PortRange: don't panic on zero values

  • Prevent panic when calling .Proto() on zero values
  • Don't iterate on zero-value port-ranges

api/types/network: add Port.Port()

This brings back the Port() method that was defined on the nat.Port type,
which was used in many places to (e.g.) do a network.JoinHostPort.

api/types/network: Port, PortRange: update godoc for "String()"

Call out that users should check if the port/port-range is valid
before consuming the value returned by String().

api/types/network: use blackbox testing for ports

- Human readable description for the release notes

api/types/network: add `Port.Port()` method to return the port-number as a string.

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

@thaJeztah thaJeztah added this to the 29.3.1 milestone Mar 12, 2026
@thaJeztah thaJeztah added area/api API status/2-code-review kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. impact/changelog kind/bugfix PR's that fix bugs area/go-sdk impact/go-sdk Noteworthy (compatibility changes) in the Go SDK labels Mar 12, 2026
Copy link
Copy Markdown
Contributor

@austinvazquez austinvazquez left a comment

Choose a reason for hiding this comment

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

lgtm!

@thaJeztah
Copy link
Copy Markdown
Member Author

oh! I need to rebase this one as it has an extra commit with the "add back replace rules" that was already merged; will do so later

- Prevent panic when calling .Proto() on zero values
- Don't iterate on zero-value port-ranges

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This brings back the Port() method that was defined on the nat.Port type,
which was used in many places to (e.g.) do a network.JoinHostPort.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Call out that users should check if the port/port-range is valid
before consuming the value returned by String().

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah merged commit 05e2957 into moby:master Mar 14, 2026
51 checks passed
@thaJeztah thaJeztah deleted the network_portfixes branch March 14, 2026 00:07
@vvoland vvoland removed the area/api API label Apr 3, 2026
xingfanxia added a commit to xingfanxia/omni that referenced this pull request Apr 9, 2026
Without this, fresh installs hit a moby 29.x daemon panic:
compose expands the unset "${TELEGRAM_CONNECTOR_PORT}" in the
telegram-connector's `expose:` field to an empty string, then
creates the container on-disk with ExposedPorts: { "": {} }.

Every subsequent `ContainerStart` call deserializes that bad
config, constructs a zero-value network.Port{}, and calls
Port.Proto() — which dereferences a zero unique.Handle[IPProtocol]
and nil-pointer-panics at container_operations.go:113.

The moby fix (moby/moby#52165) is on master but has not been
backported to docker-29.x as of 29.4.0, so the defensive move
is to make sure the env var is always defined.

4015 continues the 4xxx connector-port sequence
(4013=filesystem, 4014=nextcloud, 4015=telegram).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
xingfanxia added a commit to xingfanxia/omni that referenced this pull request Apr 9, 2026
Without this, fresh installs hit a moby 29.x daemon panic:
compose expands the unset "${TELEGRAM_CONNECTOR_PORT}" in the
telegram-connector's `expose:` field to an empty string, then
creates the container on-disk with ExposedPorts: { "": {} }.

Every subsequent `ContainerStart` call deserializes that bad
config, constructs a zero-value network.Port{}, and calls
Port.Proto() — which dereferences a zero unique.Handle[IPProtocol]
and nil-pointer-panics at container_operations.go:113.

The moby fix (moby/moby#52165) is on master but has not been
backported to docker-29.x as of 29.4.0, so the defensive move
is to make sure the env var is always defined.

4015 continues the 4xxx connector-port sequence
(4013=filesystem, 4014=nextcloud, 4015=telegram).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
xingfanxia added a commit to xingfanxia/omni that referenced this pull request Apr 10, 2026
Without this, fresh installs hit a moby 29.x daemon panic:
compose expands the unset "${TELEGRAM_CONNECTOR_PORT}" in the
telegram-connector's `expose:` field to an empty string, then
creates the container on-disk with ExposedPorts: { "": {} }.

Every subsequent `ContainerStart` call deserializes that bad
config, constructs a zero-value network.Port{}, and calls
Port.Proto() — which dereferences a zero unique.Handle[IPProtocol]
and nil-pointer-panics at container_operations.go:113.

The moby fix (moby/moby#52165) is on master but has not been
backported to docker-29.x as of 29.4.0, so the defensive move
is to make sure the env var is always defined.

4015 continues the 4xxx connector-port sequence
(4013=filesystem, 4014=nextcloud, 4015=telegram).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
xingfanxia added a commit to xingfanxia/omni that referenced this pull request Apr 10, 2026
Without this, fresh installs hit a moby 29.x daemon panic:
compose expands the unset "${TELEGRAM_CONNECTOR_PORT}" in the
telegram-connector's `expose:` field to an empty string, then
creates the container on-disk with ExposedPorts: { "": {} }.

Every subsequent `ContainerStart` call deserializes that bad
config, constructs a zero-value network.Port{}, and calls
Port.Proto() — which dereferences a zero unique.Handle[IPProtocol]
and nil-pointer-panics at container_operations.go:113.

The moby fix (moby/moby#52165) is on master but has not been
backported to docker-29.x as of 29.4.0, so the defensive move
is to make sure the env var is always defined.

4015 continues the 4xxx connector-port sequence
(4013=filesystem, 4014=nextcloud, 4015=telegram).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/go-sdk area/networking Networking ci/validate-only impact/changelog impact/go-sdk Noteworthy (compatibility changes) in the Go SDK kind/bugfix PR's that fix bugs kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. module/api module/client status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants