Repository: amir20/dozzle (language: go)

Issue:
Error at startup :  SIGSEGV: segmentation violation
### 🔍 Check for existing issues

- [x] Completed

### How is Dozzle deployed?

Remote Hosts

### 📦 Dozzle version

v8.11.0

### ✅ Command used to run Dozzle

services:
  logs:
    container_name: dozzle-app
    image: amir20/dozzle:latest
    networks:
      - socket
      - proxy
    environment:
      - DOZZLE_REMOTE_HOST=tcp://dozzle-dockersocket:2375
    restart: unless-stopped
    depends_on:
      - dockersocket
    labels:
      traefik.enable: true
      traefik.http.routers.logs.entryPoints: https
      traefik.http.routers.logs.middlewares: local@file

  dockersocket:
    container_name: dozzle-dockersocket
    environment:
      CONTAINERS: 1
      INFO: 1
    image: tecnativa/docker-socket-proxy
    networks:
      - socket
    restart: unless-stopped
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"

networks:
  socket:
    driver: bridge
    external: false
  proxy:
    driver: bridge
    external: true

### 🐛 Describe the bug / provide steps to reproduce it

This error appears at container startup:

dozzle-app           | {"level":"info","time":"2025-02-13T18:51:37Z","message":"Dozzle version v8.11.0"}
dozzle-app           | {"level":"info","time":"2025-02-13T18:51:37Z","message":"Consider using Dozzle's remote agent to manage remote hosts. See https://dozzle.dev/guide/agent for more information"}
dozzle-app           | {"level":"info","host":{"name":"dozzle-dockersocket","id":"tcp:dozzle-dockersocket:2375","nCPU":0,"memTotal":0,"endpoint":"tcp://dozzle-dockersocket:2375","dockerVersion":"","type":"","available":false},"time":"2025-02-13T18:51:37Z","message":"Adding remote host"}
dozzle-dockersocket  | ::ffff:172.21.0.3:49762 [13/Feb/2025:18:51:37.843] dockerfrontend dockerbackend/dockersocket 0/0/0/0/0 200 292 - - ---- 1/1/0/0/0 0/0 "HEAD /_ping HTTP/1.1"
dozzle-dockersocket  | ::ffff:172.21.0.3:49762 [13/Feb/2025:18:51:37.844] dockerfrontend dockerbackend/dockersocket 0/0/0/9/9 200 8487 - - ---- 1/1/0/0/0 0/0 "GET /v1.47/info HTTP/1.1"
dozzle-dockersocket  | ::ffff:172.21.0.3:49762 [13/Feb/2025:18:51:37.855] dockerfrontend dockerbackend/dockersocket 0/0/0/9/9 200 65501 - - ---- 1/1/0/0/0 0/0 "GET /v1.47/containers/json?all=1 HTTP/1.1"
dozzle-app           | {"level":"info","clients":1,"time":"2025-02-13T18:51:37Z","message":"Connected to Docker"}
dozzle-app           | panic: runtime error: invalid memory address or nil pointer dereference
dozzle-app           | [signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0xa8de35]
dozzle-app           |
dozzle-app           | goroutine 52 [running]:
dozzle-app           | github.com/amir20/dozzle/internal/docker.(*DockerClient).Host(0x0)
dozzle-app           |  /dozzle/internal/docker/client.go:296 +0x55
dozzle-app           | github.com/amir20/dozzle/internal/support/cli.StartEvent({{0x1f0f937, 0x5}, {0x1dce533, 0x1}, {0x0, 0x0}, {0x1e47623, 0x4}, {0x1f546dd, 0x4}, ...}, ...)
dozzle-app           |  /dozzle/internal/support/cli/analytics.go:29 +0x1ae
dozzle-app           | created by main.main in goroutine 1
dozzle-app           |  /dozzle/main.go:177 +0x12d9
dozzle-dockersocket  | ::ffff:172.21.0.3:49762 [13/Feb/2025:18:51:37.868] dockerfrontend dockerbackend/dockersocket 0/0/0/8/8 200 16302 - - CD-- 1/1/0/0/0 0/0 "GET /v1.47/containers/json?all=1 HTTP/1.1"

### 💻 Environment

Client: Docker Engine - Community
 Version:    27.2.0
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.16.2
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.29.2
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

### 📸 If applicable, add screenshots to help explain your bug

_No response_

### 📜 If applicable, attach your Dozzle logs. You many need to enable debug mode. See https://dozzle.dev/guide/debugging.

_No response_


Discussion / hints:
Dozzle works fine using v8.10.7
Having this same issue when starting with the latest version v8.11.0.

```dozzle  | {"level":"info","time":"2025-02-13T19:53:42Z","message":"Dozzle version v8.11.0"}
dozzle  | {"level":"info","time":"2025-02-13T19:53:42Z","message":"Consider using Dozzle's remote agent to manage remote hosts. See https://dozzle.dev/guide/agent for more information"}
dozzle  | {"level":"info","host":{"name":"argon","id":"tcp:socket-proxy:2375","nCPU":0,"memTotal":0,"endpoint":"tcp://socket-proxy:2375","dockerVersion":"","type":"","available":false},"time":"2025-02-13T19:53:42Z","message":"Adding remote host"}
dozzle  | {"level":"info","clients":1,"time":"2025-02-13T19:53:42Z","message":"Connected to Docker"}
dozzle  | {"level":"info","time":"2025-02-13T19:53:42Z","message":"Accepting connections on :8080"}
dozzle  | panic: runtime error: invalid memory address or nil pointer dereference
dozzle  | [signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0xa8de35]
dozzle  |
dozzle  | goroutine 16 [running]:
dozzle  | github.com/amir20/dozzle/internal/docker.(*DockerClient).Host(0x0)
dozzle  |       /dozzle/internal/docker/client.go:296 +0x55
dozzle  | github.com/amir20/dozzle/internal/support/cli.StartEvent({{0x1f0f937, 0x5}, {0x1dce533, 0x1}, {0x0, 0x0}, {0x1e47623, 0x4}, {0x1f546dd, 0x4}, ...}, ...)
dozzle  |       /dozzle/internal/support/cli/analytics.go:29 +0x1ae
dozzle  | created by main.main in goroutine 1
dozzle  |       /dozzle/main.go:177 +0x12d9
dozzle  | {"level":"info","time":"2025-02-13T19:53:43Z","message":"Dozzle version v8.11.0"}
dozzle  | {"level":"info","time":"2025-02-13T19:53:43Z","message":"Consider using Dozzle's remote agent to manage remote hosts. See https://dozzle.dev/guide/agent for more information"}
dozzle exited with code 0```
Yea, I am investigating it. Something weird is happening that I don't see it always. 

Fix patch:
diff --git a/internal/support/cli/clients.go b/internal/support/cli/clients.go
index b716992ecb23..98f8212a6218 100644
--- a/internal/support/cli/clients.go
+++ b/internal/support/cli/clients.go
@@ -11,7 +11,7 @@ import (
 	"github.com/rs/zerolog/log"
 )
 
-func CreateMultiHostService(embeddedCerts embed.FS, args Args) (container.Client, *docker_support.MultiHostService) {
+func CreateMultiHostService(embeddedCerts embed.FS, args Args) *docker_support.MultiHostService {
 	var clients []container_support.ClientService
 	if len(args.RemoteHost) > 0 {
 		log.Info().Msg(`Consider using Dozzle's remote agent to manage remote hosts. See https://dozzle.dev/guide/agent for more information`)
@@ -48,6 +48,7 @@ func CreateMultiHostService(embeddedCerts embed.FS, args Args) (container.Client
 			log.Debug().Msg("Adding local Docker Engine")
 			clients = append(clients, docker_support.NewDockerClientService(localClient, args.Filter))
 		}
+		go StartEvent(args, "server", localClient, "")
 	}
 
 	certs, err := ReadCertificates(embeddedCerts)
@@ -56,5 +57,5 @@ func CreateMultiHostService(embeddedCerts embed.FS, args Args) (container.Client
 	}
 
 	clientManager := docker_support.NewRetriableClientManager(args.RemoteAgent, args.Timeout, certs, clients...)
-	return localClient, docker_support.NewMultiHostService(clientManager, args.Timeout)
+	return docker_support.NewMultiHostService(clientManager, args.Timeout)
 }
diff --git a/main.go b/main.go
index 2b30cacaf00c..d6d0c03316c8 100644
--- a/main.go
+++ b/main.go
@@ -16,7 +16,6 @@ import (
 
 	"github.com/amir20/dozzle/internal/agent"
 	"github.com/amir20/dozzle/internal/auth"
-	"github.com/amir20/dozzle/internal/container"
 	"github.com/amir20/dozzle/internal/docker"
 	"github.com/amir20/dozzle/internal/healthcheck"
 	"github.com/amir20/dozzle/internal/k8s"
@@ -167,14 +166,13 @@ func main() {
 
 	var hostService web.HostService
 	if args.Mode == "server" {
-		var localClient container.Client
-		localClient, multiHostService := cli.CreateMultiHostService(certs, args)
+
+		multiHostService := cli.CreateMultiHostService(certs, args)
 		if multiHostService.TotalClients() == 0 {
 			log.Fatal().Msg("Could not connect to any Docker Engine")
 		} else {
 			log.Info().Int("clients", multiHostService.TotalClients()).Msg("Connected to Docker")
 		}
-		go cli.StartEvent(args, "server", localClient, "")
 		hostService = multiHostService
 	} else if args.Mode == "swarm" {
 		localClient, err := docker.NewLocalClient("")


Test patch: