Skip to content

fix(docker): guard nil NetworkSettings in Executor network methods - #61

Merged
jasoet merged 1 commit into
nextfrom
fix/docker-network-nil-guards
Aug 17, 2026
Merged

fix(docker): guard nil NetworkSettings in Executor network methods#61
jasoet merged 1 commit into
nextfrom
fix/docker-network-nil-guards

Conversation

@jasoet

@jasoet jasoet commented Aug 17, 2026

Copy link
Copy Markdown
Owner

Problem

container.InspectResponse.NetworkSettings is a pointer, and the daemon leaves it nil for containers without networking (--network=none, and some podman responses).

Four exported Executor methods dereferenced it unconditionally and panicked:

method line
MappedPort network.go:86
GetAllPorts network.go:147
GetNetworks network.go:175
GetIPAddress network.go:205,212

ContainerTarget.State (target.go:87) already guards this exact field — these four were the gap. Recorded as "docker NetworkSettings parity" in docs/plans/2026-07-22-v3-audit-backlog.md.

Change

The projection logic was entangled with the client call, which is why the nil case had never been tested — it needs a live daemon to reach. Extracted four pure functions of an inspect response (portBinding, allPortBindings, networkNames, networkIPAddress) and guarded there, so the nil path is unit-testable without Docker.

Behaviour:

  • GetAllPorts / GetNetworks return an empty map/slice instead of panicking — callers range over the result, so nil would be a second footgun.
  • MappedPort / GetIPAddress return their existing not-found errors unchanged.
  • Also stopped dereferencing nil EndpointSettings values inside the Networks map, which was a second latent panic.

No public signature changes.

Tests (written first, observed failing)

New docker/network_test.go — the first run failed to compile (undefined: portBinding, …), driving the extraction. 17 cases covering bound/unbound/missing ports, named vs first-available network lookup, nil NetworkSettings, and nil EndpointSettings.

These raise docker's unit coverage without needing a daemon, which matters since the package sat at 41% precisely because most paths require one.

Verification

go test ./docker/ passes; golangci-lint run ./docker/... 0 issues. Full task ci:check green on this change.

InspectResponse.NetworkSettings is a pointer and the daemon leaves it nil for
containers without networking (--network=none, and some podman responses).
MappedPort, GetAllPorts, GetNetworks and GetIPAddress dereferenced it
unconditionally and panicked instead of returning an error. ContainerTarget
already tolerates this (target.go State); these four methods did not.

Move the projection out of the client calls into pure functions of an inspect
response, which is what makes the nil case unit-testable without a live daemon,
and guard there. GetAllPorts and GetNetworks now return an empty map/slice
rather than panicking, since callers range over the result; MappedPort and
GetIPAddress return their existing not-found errors.

Also stop dereferencing nil EndpointSettings values inside the Networks map.
@jasoet
jasoet merged commit 941c7ba into next Aug 17, 2026
1 check passed
@jasoet
jasoet deleted the fix/docker-network-nil-guards branch August 17, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant