Skip to content

Commit

Permalink
Merge pull request #45903 from thaJeztah/24.0_backport_fix_volume_npe
Browse files Browse the repository at this point in the history
[24.0 backport] daemon: daemon.prepareMountPoints(): fix panic if mount is not a volume
  • Loading branch information
neersighted committed Jul 7, 2023
2 parents 1d9c861 + d3893b5 commit 4ffc614
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions daemon/mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func (daemon *Daemon) prepareMountPoints(container *container.Container) error {
if err := daemon.lazyInitializeVolume(container.ID, config); err != nil {
return err
}
if config.Volume == nil {
// FIXME(thaJeztah): should we check for config.Type here as well? (i.e., skip bind-mounts etc)
continue
}
if alive {
log.G(context.TODO()).WithFields(logrus.Fields{
"container": container.ID,
Expand Down
18 changes: 18 additions & 0 deletions integration/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,24 @@ func testLiveRestoreVolumeReferences(t *testing.T) {
err = c.VolumeRemove(ctx, v.Name, false)
assert.NilError(t, err)
})

// Make sure that we don't panic if the container has bind-mounts
// (which should not be "restored")
// Regression test for https://github.com/moby/moby/issues/45898
t.Run("container with bind-mounts", func(t *testing.T) {
m := mount.Mount{
Type: mount.TypeBind,
Source: os.TempDir(),
Target: "/foo",
}
cID := container.Run(ctx, t, c, container.WithMount(m), container.WithCmd("top"))
defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})

d.Restart(t, "--live-restore", "--iptables=false")

err := c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})
assert.NilError(t, err)
})
}

func TestDaemonDefaultBridgeWithFixedCidrButNoBip(t *testing.T) {
Expand Down

0 comments on commit 4ffc614

Please sign in to comment.