Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[docker-29.x backport] daemon: buildCreateEndpointOptions: fix panic with "publish all"#51691

Merged
thaJeztah merged 2 commits intomoby:docker-29.xfrom
vvoland:51683-docker-29.x
Dec 11, 2025
Merged

[docker-29.x backport] daemon: buildCreateEndpointOptions: fix panic with "publish all"#51691
thaJeztah merged 2 commits intomoby:docker-29.xfrom
vvoland:51683-docker-29.x

Conversation

@vvoland
Copy link
Contributor

@vvoland vvoland commented Dec 11, 2025

This code was added in 85b260f, but didn't account for maps.Clone returning a nil map if the map cloned was nil.

This could lead to a panic, similar to the panic that was fixed in 7517464;

panic: assignment to entry in nil map

goroutine 498 [running]:

github.com/moby/moby/v2/daemon.buildPortsRelatedCreateEndpointOptions(0x400042f348, 0xaaaabcc8f458?, 0x40006feb40)
    /root/build-deb/engine/daemon/network.go:1047 +0x844
github.com/moby/moby/v2/daemon.buildCreateEndpointOptions(0x400042f348, 0x4001015040, 0x400027d320, 0x40006feb40, {0x0, 0x0, 0x4001506cb8?})
    /root/build-deb/engine/daemon/network.go:988 +0x20c
github.com/moby/moby/v2/daemon.(*Daemon).connectToNetwork(0x4000898008, {0xaaaabe21d9f8, 0x4000f12b10}, 0x400089a008, 0x400042f348, {0x400077a9f0, 0x6}, 0x400027d320)
    /root/build-deb/engine/daemon/container_operations.go:738 +0x66c
github.com/moby/moby/v2/daemon.(*Daemon).allocateNetwork(0x4000898008, {0xaaaabe21d9f8, 0x4000f12b10}, 0x400089a008, 0x400042f348)
    /root/build-deb/engine/daemon/container_operations.go:421 +0x298
github.com/moby/moby/v2/daemon.(*Daemon).initializeCreatedTask(0x4000898008, {0xaaaabe21d9f8, 0x4000f12b10}, 0x400089a008, {0xaaaabe23dc60, 0x4000eb21c8}, 0x400042f348, 0xaaaabd4db3df?)
    /root/build-deb/engine/daemon/start_linux.go:37 +0x260
github.com/moby/moby/v2/daemon.(*Daemon).containerStart(0x4000898008, {0xaaaabe21d9c0, 0xaaaabfa05300}, 0x400089a008, 0x400042f348, {0x0, 0x0}, {0x0, 0x0}, 0x1)
    /root/build-deb/engine/daemon/start.go:242 +0xba8
github.com/moby/moby/v2/daemon.(*Daemon).restore.func4(0x400042f348, 0x400117f1f0)
    /root/build-deb/engine/daemon/daemon.go:633 +0x308
created by github.com/moby/moby/v2/daemon.(*Daemon).restore in goroutine 1
    /root/build-deb/engine/daemon/daemon.go:607 +0x5ec

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes

- Don't crash when starting a container created via the API before upgrade to v29.1.2, with `PublishAll` and a nil `PortBindings` map.

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

@vvoland vvoland added this to the 29.1.3 milestone Dec 11, 2025
@vvoland vvoland self-assigned this Dec 11, 2025
This code was added in 85b260f, but didn't
account for maps.Clone returning a `nil` map if the map cloned was `nil`.

This could lead to a panic, similar to the panic that was fixed in
7517464;

    panic: assignment to entry in nil map

    goroutine 498 [running]:

    github.com/moby/moby/v2/daemon.buildPortsRelatedCreateEndpointOptions(0x400042f348, 0xaaaabcc8f458?, 0x40006feb40)
        /root/build-deb/engine/daemon/network.go:1047 +0x844
    github.com/moby/moby/v2/daemon.buildCreateEndpointOptions(0x400042f348, 0x4001015040, 0x400027d320, 0x40006feb40, {0x0, 0x0, 0x4001506cb8?})
        /root/build-deb/engine/daemon/network.go:988 +0x20c
    github.com/moby/moby/v2/daemon.(*Daemon).connectToNetwork(0x4000898008, {0xaaaabe21d9f8, 0x4000f12b10}, 0x400089a008, 0x400042f348, {0x400077a9f0, 0x6}, 0x400027d320)
        /root/build-deb/engine/daemon/container_operations.go:738 +0x66c
    github.com/moby/moby/v2/daemon.(*Daemon).allocateNetwork(0x4000898008, {0xaaaabe21d9f8, 0x4000f12b10}, 0x400089a008, 0x400042f348)
        /root/build-deb/engine/daemon/container_operations.go:421 +0x298
    github.com/moby/moby/v2/daemon.(*Daemon).initializeCreatedTask(0x4000898008, {0xaaaabe21d9f8, 0x4000f12b10}, 0x400089a008, {0xaaaabe23dc60, 0x4000eb21c8}, 0x400042f348, 0xaaaabd4db3df?)
        /root/build-deb/engine/daemon/start_linux.go:37 +0x260
    github.com/moby/moby/v2/daemon.(*Daemon).containerStart(0x4000898008, {0xaaaabe21d9c0, 0xaaaabfa05300}, 0x400089a008, 0x400042f348, {0x0, 0x0}, {0x0, 0x0}, 0x1)
        /root/build-deb/engine/daemon/start.go:242 +0xba8
    github.com/moby/moby/v2/daemon.(*Daemon).restore.func4(0x400042f348, 0x400117f1f0)
        /root/build-deb/engine/daemon/daemon.go:633 +0x308
    created by github.com/moby/moby/v2/daemon.(*Daemon).restore in goroutine 1
        /root/build-deb/engine/daemon/daemon.go:607 +0x5ec

Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit 695010b)
Signed-off-by: Paweł Gronowski <[email protected]>
Make sure PortBindings is not a nil-map to match the behavior
we have when creating a container;
https://github.com/moby/moby/blob/c64b781df2387bea01720a3a3411f7d29dd40ea8/daemon/internal/runconfig/config.go#L30-L47

Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit 2a19166)
Signed-off-by: Paweł Gronowski <[email protected]>
@vvoland
Copy link
Contributor Author

vvoland commented Dec 11, 2025

Hmm this one keeps reappearing


=== Failed
=== FAIL: amd64.docker.docker.integration.container TestDaemonRestartKillContainers/live-restore=true/container_with_restart=always_and_with_healthcheck/stop-daemon (2.14s)
    restart_test.go:115: expected exit code 0, got 1
    restart_test.go:115: stdout: 
    restart_test.go:115: stderr: touch: /tmp/unhealthy: No such file or directory
    --- FAIL: TestDaemonRestartKillContainers/live-restore=true/container_with_restart=always_and_with_healthcheck/stop-daemon (2.14s)

=== FAIL: amd64.docker.docker.integration.container TestDaemonRestartKillContainers (0.00s)

Copy link
Member

@thaJeztah thaJeztah 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 thaJeztah merged commit 8f33623 into moby:docker-29.x Dec 11, 2025
395 of 420 checks passed
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.

4 participants