Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

panic: duplicate metrics collector registration attempted #1012

Closed
bb opened this issue Feb 18, 2025 · 3 comments · Fixed by #1013
Closed

panic: duplicate metrics collector registration attempted #1012

bb opened this issue Feb 18, 2025 · 3 comments · Fixed by #1013

Comments

@bb
Copy link

bb commented Feb 18, 2025

I'm building Mercure using this Dockerfile:

FROM caddy:2-builder AS builder

RUN \
    apk update && \
    apk add gcc brotli-dev musl-dev && \
    CGO_ENABLED=1 \
    xcaddy build \
    --with github.com/dunglas/mercure/caddy \
    --with github.com/dunglas/caddy-cbrotli \
    --with github.com/evilmartians/caddy_anycable


FROM caddy:2

RUN apk add --no-cache brotli-libs

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

With newer Mercure versions, I'm getting a panic. It might be related to having two domains with mercure configured in my Caddyfile, because with only one it's fine.

I'm guessing it might be related to this commit: 107e6b8

panic: duplicate metrics collector registration attempted

goroutine 1 [running]:
github.com/prometheus/client_golang/prometheus.(*Registry).MustRegister(0xc00099c3c0, {0xc00091cf70?, 0x0?, 0x0?})
	github.com/prometheus/client_golang@v1.20.5/prometheus/registry.go:406 +0x66
github.com/dunglas/mercure.NewPrometheusMetrics({0x2b2e740?, 0xc00099c3c0?})
	github.com/dunglas/mercure@v0.18.3/metrics.go:65 +0x2b7
github.com/dunglas/mercure/caddy.(*Mercure).Provision(0xc00054b7a0, {{0x2b33730, 0xc000021620}, 0xc0002c2cf0, 0xc0005529c0, {0xc0002eec40, 0x3, 0x4}, {0x0, 0x0, ...}, ...})
	github.com/dunglas/mercure/caddy@v0.18.3/mercure.go:190 +0x39
github.com/caddyserver/caddy/v2.Context.LoadModuleByID({{0x2b33730, 0xc000021620}, 0xc0002c2cf0, 0xc0005529c0, {0xc0002eec40, 0x3, 0x4}, {0x0, 0x0, 0x0}, ...}, ...)
	github.com/caddyserver/caddy/v2@v2.9.1/context.go:391 +0x695
github.com/caddyserver/caddy/v2.Context.loadModuleInline({{0x2b33730, 0xc000021620}, 0xc0002c2cf0, 0xc0005529c0, {0xc000473be0, 0x2, 0x2}, {0x0, 0x0, 0x0}, ...}, ...)
	github.com/caddyserver/caddy/v2@v2.9.1/context.go:441 +0xf0
github.com/caddyserver/caddy/v2.Context.LoadModule({{0x2b33730, 0xc000021620}, 0xc0002c2cf0, 0xc0005529c0, {0xc000473be0, 0x2, 0x2}, {0x0, 0x0, 0x0}, ...}, ...)
	github.com/caddyserver/caddy/v2@v2.9.1/context.go:222 +0x706
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Route).ProvisionHandlers(0xc0005462d0, {{0x2b33730, 0xc000021620}, 0xc0002c2cf0, 0xc0005529c0, {0xc000473be0, 0x2, 0x2}, {0x0, 0x0, ...}, ...}, ...)
	github.com/caddyserver/caddy/v2@v2.9.1/modules/caddyhttp/routes.go:154 +0x71
github.com/caddyserver/caddy/v2/modules/caddyhttp.RouteList.ProvisionHandlers({0xc0005462d0, 0x1, 0x7f876262c108?}, {{0x2b33730, 0xc000021620}, 0xc0002c2cf0, 0xc0005529c0, {0xc000473be0, 0x2, 0x2}, ...}, ...)
	github.com/caddyserver/caddy/v2@v2.9.1/modules/caddyhttp/routes.go:212 +0xa9
github.com/caddyserver/caddy/v2/modules/caddyhttp.RouteList.Provision({0xc0005462d0, 0x1, 0x1}, {{0x2b33730, 0xc000021620}, 0xc0002c2cf0, 0xc0005529c0, {0xc000473be0, 0x2, 0x2}, ...})
	github.com/caddyserver/caddy/v2@v2.9.1/modules/caddyhttp/routes.go:189 +0xb2
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Subroute).Provision(0xc000473ba0, {{0x2b33730, 0xc000021620}, 0xc0002c2cf0, 0xc0005529c0, {0xc000473be0, 0x2, 0x2}, {0x0, 0x0, ...}, ...})
	github.com/caddyserver/caddy/v2@v2.9.1/modules/caddyhttp/subroute.go:58 +0x5f
github.com/caddyserver/caddy/v2.Context.LoadModuleByID({{0x2b33730, 0xc000021620}, 0xc0002c2cf0, 0xc0005529c0, {0xc000473be0, 0x2, 0x2}, {0x0, 0x0, 0x0}, ...}, ...)
	github.com/caddyserver/caddy/v2@v2.9.1/context.go:391 +0x695
github.com/caddyserver/caddy/v2.Context.loadModuleInline({{0x2b33730, 0xc000021620}, 0xc0002c2cf0, 0xc0005529c0, {0xc00099b7e0, 0x1, 0x1}, {0x0, 0x0, 0x0}, ...}, ...)
	github.com/caddyserver/caddy/v2@v2.9.1/context.go:441 +0xf0
github.com/caddyserver/caddy/v2.Context.LoadModule({{0x2b33730, 0xc000021620}, 0xc0002c2cf0, 0xc0005529c0, {0xc00099b7e0, 0x1, 0x1}, {0x0, 0x0, 0x0}, ...}, ...)
	github.com/caddyserver/caddy/v2@v2.9.1/context.go:222 +0x706
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Route).ProvisionHandlers(0xc0005d12a8, {{0x2b33730, 0xc000021620}, 0xc0002c2cf0, 0xc0005529c0, {0xc00099b7e0, 0x1, 0x1}, {0x0, 0x0, ...}, ...}, ...)
	github.com/caddyserver/caddy/v2@v2.9.1/modules/caddyhttp/routes.go:154 +0x71
github.com/caddyserver/caddy/v2/modules/caddyhttp.RouteList.ProvisionHandlers({0xc0005d1188, 0x3, 0x546?}, {{0x2b33730, 0xc000021620}, 0xc0002c2cf0, 0xc0005529c0, {0xc00099b7e0, 0x1, 0x1}, ...}, ...)
	github.com/caddyserver/caddy/v2@v2.9.1/modules/caddyhttp/routes.go:212 +0xa9
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*App).Provision(0xc0007ab5f0, {{0x2b33730, 0xc000021620}, 0xc0002c2cf0, 0xc0005529c0, {0xc00099b7e0, 0x1, 0x1}, {0x0, 0x0, ...}, ...})
	github.com/caddyserver/caddy/v2@v2.9.1/modules/caddyhttp/app.go:367 +0xf25
github.com/caddyserver/caddy/v2.Context.LoadModuleByID({{0x2b33768, 0xc00099c410}, 0xc0002c2cf0, 0xc0005529c0, {0xc00099b7e0, 0x1, 0x1}, {0x0, 0x0, 0x0}, ...}, ...)
	github.com/caddyserver/caddy/v2@v2.9.1/context.go:391 +0x695
github.com/caddyserver/caddy/v2.Context.App({{0x2b33768, 0xc00099c410}, 0xc0002c2cf0, 0xc0005529c0, {0x0, 0x0, 0x0}, {0x0, 0x0, 0x0}, ...}, ...)
	github.com/caddyserver/caddy/v2@v2.9.1/context.go:467 +0xee
github.com/caddyserver/caddy/v2.provisionContext.func3(...)
	github.com/caddyserver/caddy/v2@v2.9.1/caddy.go:545
github.com/caddyserver/caddy/v2.provisionContext(0xc0006693e0?, 0x1)
	github.com/caddyserver/caddy/v2@v2.9.1/caddy.go:550 +0x53c
github.com/caddyserver/caddy/v2.run(0xc?, 0x1)
	github.com/caddyserver/caddy/v2@v2.9.1/caddy.go:400 +0x78
github.com/caddyserver/caddy/v2.unsyncedDecodeAndRun({0xc0006c3600, 0x57c, 0x580}, 0x1)
	github.com/caddyserver/caddy/v2@v2.9.1/caddy.go:343 +0x145
github.com/caddyserver/caddy/v2.changeConfig({0x25345b4, 0x4}, {0x253c04f, 0x7}, {0xc0006c3080, 0x57c, 0x580}, {0x0, 0x0}, 0x1)
	github.com/caddyserver/caddy/v2@v2.9.1/caddy.go:234 +0x6b6
github.com/caddyserver/caddy/v2.Load({0xc0006c3080, 0x57c, 0x580}, 0x1)
	github.com/caddyserver/caddy/v2@v2.9.1/caddy.go:133 +0x22d
github.com/caddyserver/caddy/v2/cmd.cmdRun({0x0?})
	github.com/caddyserver/caddy/v2@v2.9.1/cmd/commandfuncs.go:235 +0x831
github.com/caddyserver/caddy/v2/cmd.init.1.func2.WrapCommandFuncForCobra.1(0xc0001adb08, {0x2534614?, 0x4?, 0x25345e4?})
	github.com/caddyserver/caddy/v2@v2.9.1/cmd/cobra.go:141 +0x2f
github.com/spf13/cobra.(*Command).execute(0xc0001adb08, {0xc000322380, 0x4, 0x4})
	github.com/spf13/cobra@v1.9.1/command.go:1015 +0xa94
github.com/spf13/cobra.(*Command).ExecuteC(0xc0001ad508)
	github.com/spf13/cobra@v1.9.1/command.go:1148 +0x40c
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/cobra@v1.9.1/command.go:1071
github.com/caddyserver/caddy/v2/cmd.Main()
	github.com/caddyserver/caddy/v2@v2.9.1/cmd/main.go:75 +0x1dd
main.main()
	caddy/main.go:14 +0xf
@dany-loveevents
Copy link

@bb Me too

@rvanlaak
Copy link

rvanlaak commented Feb 19, 2025

Impacts API Platform as well. Also see #1007 (comment)

@CedCannes
Copy link

As a temporary workaround for this issue, I have downgraded the versions of Caddy, Mercure, and Vulcain in my Dockerfile to keep my existing API Platform project operational.
Here are parts of my Dockerfile:

ARG CADDY_VERSION=2.8.4

FROM php:${PHP_VERSION}-fpm-alpine AS api_platform_php

# ... other instructions ...

RUN xcaddy build \
    --with github.com/dunglas/mercure@v0.17.1 \
    --with github.com/dunglas/mercure/caddy@v0.17.1 \
    --with github.com/dunglas/vulcain/caddy@v1.0.5

# ... other instructions ...

I hope this helps someone facing the same issue.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants