Caddy -v panic: duplicate metrics collector registration attempted

Previously working Caddy, upgraded via Brew (Mac) throws error:

1. Caddy version (caddy version): Stable 2.2.0 (bottled), HEAD from Brew / Mac Catalina 10.15.7 (19H2)

2. How I run Caddy: caddy -v gives:

panic: duplicate metrics collector registration attempted

As does anything on the command line .e.g caddy -h

Full Error list:

caddy -t
panic: duplicate metrics collector registration attempted

goroutine 1 [running]:*Registry).MustRegister(0xc0000a65f0, 0xc0007fcf90, 0x1, 0x1) +0xad +0xb2```

#### a. System environment:
Mac Catalina 10.15.7 (19H2)
Homebrew 2.5.2

#### a. Caddy File same as my one in this post:

### 3. The problem I'm having:
Previously working Caddy, upgraded via Brew (Mac) throws error when running. Cannot troubleshoot as any thing crashes it.

### 4. Error messages and/or full log output:
See above:

### 5. What I already tried:
Rebooted, same error.

### 6. Links to relevant resources:

Sorry forgot to attach caddyfile:

# Caddy 2 file for local domains and Kirby 2, Kirby 3 & static sites
# v0.1.0
# 2020/05/10
# Global Block
  email xxx

# Snippets
# Common server snippet use 'import common'
(common) {
  encode gzip
  php_fastcgi localhost:9000
  tls internal
  header * {
	    Strict-Transport-Security "max-age=31536000; includeSubdomains; preload"
        X- Frame-Options "DENY"
		X-Content-Type-Options "nosniff"
		X-Frame-Options "SAMEORIGIN"


# Kirby 2 & 3 common snippet use 'import kirby'
(kirby) {  
  @blocked {
    path *.md *.mdown /site/* /kirby/*
  redir @blocked /

# Kirby 2 snippet use 'import kirby2'
(kirby2) {
  # /panel files
  handle /panel* {
  try_files {path} {path}/ /panel/index.php?{uri}&{query}
  @notPanel {
    not path /panel*
  handle @notPanel {
    try_files {path}/ /index.php?&{query}

# Cachebuster rewrite style.123213.css => style.css 'import cachebuster'
(cachebuster) {
  @cachedFiles {
      not file
      path_regexp cached ~*(.+)\.(?:\d+)\.(js|css|jpg|svg|png)
  rewrite @cachedFiles {http.regexp.cached.1}.{http.regexp.cached.2}

# Static html site snippet use (make HTML file extension optional) 'import static'
(static) {
  @notRoot {
    not path /
  handle @notRoot {
    try_files {path}.html {path} /404.html
 try_files {path}.html {path}

# Set logging 'import logging'
(logging) {
  log {
  	output file /Users/xxx/Sites/log/log.log
  	format single_field common_log


# Virtual Hosts - domains need to be added to your hosts file

staticsite.test {
  # Repoint this to the build folder of the site you are testing 
  # Enables test the static version of the site
  root * /Users/xxx/Sites/xxx/_build/
  import common
  import static

aap.test:443 {
  root * /Users/xxx/Sites/aap
  import common
  import kirby
  import kirby2


Hi @WoofDog, sorry to see there’s a panic!

I’m not exactly sure why this is happening - there are some protections in place that should prevent this, but I may have missed something.

Can you please try with the binary from the GitHub releases

I just want to make sure that the brew package isn’t building an older release (there were some panics in the pre-releases).

If you can reproduce it, please log an issue at Sign in to GitHub · GitHub including the information from this thread.

We’re pretty sure that a change that was made in brew for Caddy broke things. See:

Yeah… based on that stack trace which is identifying the module version in a super-weird way (, I think init() is being called twice (which is totally not OK) - this is the line that’s panicing - caddy/metrics.go at master · caddyserver/caddy · GitHub - and it will panic if init() is called twice.

Many thanks @hairyhenderson and @francislavoie for your speedy replies. Read the thread over on Homebrew, sadly I’m no expert on brew, so I guess I will have to wait until the changes have been released.

I much appreciate all your help. I will advise when it has been updated and working again so it can be closed here.

@WoofDog there’s a PR in for the changes, but I’m not sure when or if they’ll accept it.

As convenient as Homebrew is, the Caddy formula is not an official distribution, and we do sometimes see issues there that aren’t present with the official macOS binaries (like here).

So unless and until the Homeberw PR is merged I would recommend using the officially-built binary instead. It’s not as convenient, to be sure, but it does work :wink:

This topic was automatically closed after 30 days. New replies are no longer allowed.