sablierapp / sablier

Start your containers on demand, shut them down automatically when there's no activity. Docker, Docker Swarm Mode and Kubernetes compatible.
https://sablierapp.dev/
GNU Affero General Public License v3.0
1.41k stars 46 forks source link

Invalid memory address in Traefik plugin with docker #432

Open nonodev96 opened 2 days ago

nonodev96 commented 2 days ago

Describe the bug With version 1.8.1 of traefik plugin sablier not working

Logs of sablier container

time="2024-10-28T16:14:44Z" level=debug msg="map[]"
time="2024-10-28T16:14:45Z" level=debug msg="received event instance nonodev96_traefik_whoami is stopped, removing from store"
time="2024-10-28T16:14:46Z" level=debug msg="map[]"
time="2024-10-28T16:14:47Z" level=debug msg="starting [traefik_whoami]..."

2024/10/28 16:14:47 [Recovery] 2024/10/28 - 16:14:47 panic recovered:
runtime error: invalid memory address or nil pointer dereference
runtime/panic.go:262 (0x471118)
runtime/signal_unix.go:900 (0x4710e8)
github.com/sablierapp/sablier/app/http/routes/strategies.go:167 (0x1a40bea)
github.com/sablierapp/sablier/app/http/routes/strategies.go:149 (0x1a409cc)
sync/map.go:501 (0x483a17)
github.com/sablierapp/sablier/app/http/routes/strategies.go:147 (0x1a40811)
github.com/sablierapp/sablier/app/http/routes/strategies.go:81 (0x1a40184)
github.com/gin-gonic/gin@v1.10.0/context.go:185 (0x920fce)
github.com/gin-gonic/gin@v1.10.0/recovery.go:102 (0x920fbb)
github.com/gin-gonic/gin@v1.10.0/context.go:185 (0x1a3ab3c)
github.com/sablierapp/sablier/app/http/middleware/logging.go:37 (0x1a3ab23)
github.com/gin-gonic/gin@v1.10.0/context.go:185 (0x91fd71)
github.com/gin-gonic/gin@v1.10.0/gin.go:633 (0x91f7e0)
github.com/gin-gonic/gin@v1.10.0/gin.go:589 (0x91f311)
net/http/server.go:3210 (0x74488d)
net/http/server.go:2092 (0x723e8f)
runtime/asm_amd64.s:1700 (0x4770c0)

Steps to reproduce

Docker version ```log Client: Version: 27.3.1 API version: 1.47 Go version: go1.22.7 Git commit: ce12230 Built: Fri Sep 20 11:39:44 2024 OS/Arch: linux/amd64 Context: default Server: Docker Desktop () Engine: Version: 27.3.1 API version: 1.47 (minimum version 1.24) Go version: go1.22.7 Git commit: 41ca978 Built: Fri Sep 20 11:41:11 2024 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.7.21 GitCommit: 472731909fa34bd7bc9c087e4c27943f9835f111 runc: Version: 1.1.13 GitCommit: v1.1.13-0-g58aa920 docker-init: Version: 0.19.0 GitCommit: de40ad0 ```
Docker compose ```yml traefik_sablier: image: sablierapp/sablier:1.8.1 container_name: "${PROJECT_NAME}_traefik_sablier" networks: - proxy - backend depends_on: - traefik command: - start - --provider.name=docker - --logging.level=trace volumes: - '/var/run/docker.sock:/var/run/docker.sock' traefik_whoami: image: traefik/whoami container_name: "${PROJECT_NAME}_traefik_whoami" networks: - proxy - backend ```
Static config traefik ```yml experimental: plugins: plugin-traefik-sablier: moduleName: "github.com/sablierapp/sablier" version: "v1.8.1" ```
Dynamic config traefik ```yml http: middlewares: app-sablier: plugin: plugin-traefik-sablier: sablierUrl: http://traefik_sablier:10000 names: traefik_whoami # Comma separated names of containers/services/deployments etc. sessionDuration: 1m dynamic: displayName: My Title # (Optional) Defaults to the middleware name showDetails: true # (Optional) Set to true or false to show details specifcally for this middleware, unset to use Sablier server defaults theme: hacker-terminal # (Optional) The theme to use refreshFrequency: 5s # (Optional) The loading page refresh frequency routers: whoami: rule: "Host(`whoami.nonodev96.dev`)" entryPoints: - websecure middlewares: - app-sablier@file # COMMENT TO TEST service: "whoami-svc" tls: {} services: whoami-svc: loadBalancer: servers: - url: "http://traefik_whoami:80" ```
acouvreur commented 2 days ago

Hello @nonodev96

When using names you should use the container name, not the service name within compose.

How to fix it ?

You can use the value that you submit as container_name. So it would be: "${PROJECT_NAME}_traefik_whoami".


The error is not clear though, it will be updated soon for better output.


My recommendation is to use group instead and register your containers via labels.

See: https://sablierapp.dev/#/providers/docker?id=register-containers

Which would be:

  traefik_sablier:
    image: sablierapp/sablier:1.8.1
    container_name: "${PROJECT_NAME}_traefik_sablier"
    networks:
      - proxy
      - backend
    depends_on:
      - traefik
    command:
      - start
      - --provider.name=docker
      - --logging.level=trace
    volumes:
      - '/var/run/docker.sock:/var/run/docker.sock'

  traefik_whoami:
    image: traefik/whoami
    container_name: "${PROJECT_NAME}_traefik_whoami"
    networks:
      - proxy
      - backend
    labels:
      - sablier.enable=true
      - sablier.group=whoami

And then change

http:
  middlewares:
    app-sablier:
      plugin:
        plugin-traefik-sablier:
          sablierUrl: http://traefik_sablier:10000
          group: whoami               # Will wake up all containers with label sablier.group=whoami
          sessionDuration: 1m
          dynamic:
            displayName: My Title       # (Optional) Defaults to the middleware name
            showDetails: true           # (Optional) Set to true or false to show details specifcally for this middleware, unset to use Sablier server defaults
            theme: hacker-terminal      # (Optional) The theme to use
            refreshFrequency: 5s        # (Optional) The loading page refresh frequency

  routers:
    whoami:
      rule: "Host(`whoami.nonodev96.dev`)"
      entryPoints:
        - websecure
      middlewares:
        - app-sablier@file # COMMENT TO TEST
      service: "whoami-svc"
      tls: {}

  services:
    whoami-svc:
      loadBalancer:
        servers:
          - url: "http://traefik_whoami:80"

Does that make sense ?

nonodev96 commented 1 day ago

I've been troubleshooting it, and it’s working now. Initially, I thought it was a bug since there was no warning.

Have you considered the possibility of using 'names' and 'group' as a YAML list instead of separating them with commas?

Thank you very much, the project is aweome!"