Skip to content

daemon: Fix panic in shutdown after daemon init fails#51943

Merged
thaJeztah merged 1 commit intomoby:masterfrom
vvoland:init-fix-panic
Jan 27, 2026
Merged

daemon: Fix panic in shutdown after daemon init fails#51943
thaJeztah merged 1 commit intomoby:masterfrom
vvoland:init-fix-panic

Conversation

@vvoland
Copy link
Contributor

@vvoland vvoland commented Jan 27, 2026

When error during daemon initialization fails before the events manager is created the daemon will panic instead of erroring out cleanly with an actual error message.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x194fcec]

goroutine 1 [running, locked to thread]:
github.com/moby/moby/v2/daemon/events.(*Events).Close(...)
	/go/src/github.com/docker/docker/daemon/events/events.go:157
github.com/moby/moby/v2/daemon.(*Daemon).Shutdown(0x40001bf908, {0x2d664f0, 0x44c87e0})
	/go/src/github.com/docker/docker/daemon/daemon.go:1505 +0x3bc
github.com/moby/moby/v2/daemon.NewDaemon.func1()
	/go/src/github.com/docker/docker/daemon/daemon.go:907 +0x44
github.com/moby/moby/v2/daemon.NewDaemon({0x2d66560, 0x4000051c20}, 0x40004a6108, 0x40006fe810, 0x4000318700)
	/go/src/github.com/docker/docker/daemon/daemon.go:1371 +0x2130
github.com/moby/moby/v2/daemon/command.(*daemonCLI).start(0x4000051bd0, {0x2d664f0, 0x44c87e0})
	/go/src/github.com/docker/docker/daemon/command/daemon.go:264 +0xb90
github.com/moby/moby/v2/daemon/command.runDaemon(...)
	/go/src/github.com/docker/docker/daemon/command/docker_unix.go:13
github.com/moby/moby/v2/daemon/command.newDaemonCommand.func1(0x4000381808, {0x40006ac780?, 0x7?, 0x287f0b1?})
	/go/src/github.com/docker/docker/daemon/command/docker.go:48 +0xb0
github.com/spf13/cobra.(*Command).execute(0x4000381808, {0x4000050060, 0x4, 0x4})
	/go/src/github.com/docker/docker/vendor/github.com/spf13/cobra/command.go:1015 +0x7d4
github.com/spf13/cobra.(*Command).ExecuteC(0x4000381808)
	/go/src/github.com/docker/docker/vendor/github.com/spf13/cobra/command.go:1148 +0x350
github.com/spf13/cobra.(*Command).Execute(...)
	/go/src/github.com/docker/docker/vendor/github.com/spf13/cobra/command.go:1071
github.com/spf13/cobra.(*Command).ExecuteContext(...)
	/go/src/github.com/docker/docker/vendor/github.com/spf13/cobra/command.go:1064
github.com/moby/moby/v2/daemon/command.daemonRunner.Run({0x2d35440?}, {0x2d664f0, 0x44c87e0})
	/go/src/github.com/docker/docker/daemon/command/docker.go:97 +0x6c
main.main()
	/go/src/github.com/docker/docker/cmd/dockerd/main.go:35 +0x108

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes

Fix panic after failed daemon initialization

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

When error during daemon initialization fails before the events manager
is created the daemon will panic instead of erroring out cleanly with
an actual error message.

```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x194fcec]

goroutine 1 [running, locked to thread]:
github.com/moby/moby/v2/daemon/events.(*Events).Close(...)
	/go/src/github.com/docker/docker/daemon/events/events.go:157
github.com/moby/moby/v2/daemon.(*Daemon).Shutdown(0x40001bf908, {0x2d664f0, 0x44c87e0})
	/go/src/github.com/docker/docker/daemon/daemon.go:1505 +0x3bc
github.com/moby/moby/v2/daemon.NewDaemon.func1()
	/go/src/github.com/docker/docker/daemon/daemon.go:907 +0x44
github.com/moby/moby/v2/daemon.NewDaemon({0x2d66560, 0x4000051c20}, 0x40004a6108, 0x40006fe810, 0x4000318700)
	/go/src/github.com/docker/docker/daemon/daemon.go:1371 +0x2130
github.com/moby/moby/v2/daemon/command.(*daemonCLI).start(0x4000051bd0, {0x2d664f0, 0x44c87e0})
	/go/src/github.com/docker/docker/daemon/command/daemon.go:264 +0xb90
github.com/moby/moby/v2/daemon/command.runDaemon(...)
	/go/src/github.com/docker/docker/daemon/command/docker_unix.go:13
github.com/moby/moby/v2/daemon/command.newDaemonCommand.func1(0x4000381808, {0x40006ac780?, 0x7?, 0x287f0b1?})
	/go/src/github.com/docker/docker/daemon/command/docker.go:48 +0xb0
github.com/spf13/cobra.(*Command).execute(0x4000381808, {0x4000050060, 0x4, 0x4})
	/go/src/github.com/docker/docker/vendor/github.com/spf13/cobra/command.go:1015 +0x7d4
github.com/spf13/cobra.(*Command).ExecuteC(0x4000381808)
	/go/src/github.com/docker/docker/vendor/github.com/spf13/cobra/command.go:1148 +0x350
github.com/spf13/cobra.(*Command).Execute(...)
	/go/src/github.com/docker/docker/vendor/github.com/spf13/cobra/command.go:1071
github.com/spf13/cobra.(*Command).ExecuteContext(...)
	/go/src/github.com/docker/docker/vendor/github.com/spf13/cobra/command.go:1064
github.com/moby/moby/v2/daemon/command.daemonRunner.Run({0x2d35440?}, {0x2d664f0, 0x44c87e0})
	/go/src/github.com/docker/docker/daemon/command/docker.go:97 +0x6c
main.main()
	/go/src/github.com/docker/docker/cmd/dockerd/main.go:35 +0x108
```

Signed-off-by: Paweł Gronowski <[email protected]>
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

was this a regression?

@thaJeztah thaJeztah merged commit 0b83aa1 into moby:master Jan 27, 2026
222 of 228 checks passed
@vvoland
Copy link
Contributor Author

vvoland commented Jan 27, 2026

I don't think it was a 29.2 regression.

@vvoland vvoland modified the milestones: 29.3.0, 29.2.1 Jan 29, 2026
@alialobidm

This comment has been minimized.

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.

3 participants