Remote Caddyfile - invalid memory address or nil pointer dereference

1. The problem I’m having:

Hi, I am trying to load a Caddyfile from a remote URL but getting the below error
Initial Caddyfile

{
      auto_https disable_redirects
      admin :2019
    }

I have separate service that does a POST request to port 2019 with the below payload

{
    "admin": {
      "config": {
        "load": {
          "module": "http",
          "url": "http://localhost:56417/caddyfile"
        }
      }
    }
  }

The URl “http://localhost:56417/caddyfile” returns the below with “content-type”: “text/caddyfile; charset=utf-8”

  :8080 {
    respond /health "Ok" 200
    }
    :443 {
    respond /health "Ok" 200
    }

2. Error messages and/or full log output:

PASTE OVER THIS, BETWEEN THE ``` LINES.
2023/04/19 18:06:51.068	INFO	admin	admin endpoint started	{"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2023/04/19 18:06:53.394	INFO	http: panic serving [::1]:56479: runtime error: invalid memory address or nil pointer dereference
goroutine 39 [running]:
net/http.(*conn).serve.func1()
	net/http/server.go:1850 +0xbf
panic({0x2497720, 0x36d65a0})
	runtime/panic.go:890 +0x262
github.com/caddyserver/caddy/v2.(*Logging).Logger(0xc0004af920, {0x0?, 0x0?})
	github.com/caddyserver/caddy/v2@v2.6.2/logging.go:202 +0x41
github.com/caddyserver/caddy/v2.Context.Logger({{0x2a6b390, 0xc000694040}, 0xc0004af8f0, 0xc0004ba370, {0x0, 0x0, 0x0}, {0x0, 0x0, 0x0}}, ...)
	github.com/caddyserver/caddy/v2@v2.6.2/context.go:478 +0xa5
github.com/caddyserver/caddy/v2/caddyconfig.HTTPLoader.LoadConfig({{0x0, 0x0}, {0xc0004d8560, 0x20}, 0x0, 0x0, 0x0}, {{0x2a6b390, 0xc000694040}, 0xc0004af8f0, ...})
	github.com/caddyserver/caddy/v2@v2.6.2/caddyconfig/httploader.go:116 +0x89f
github.com/caddyserver/caddy/v2.finishSettingUp({{0x2a6b390, 0xc000694040}, 0xc0004af8f0, 0xc0004ba370, {0x0, 0x0, 0x0}, {0x0, 0x0, 0x0}}, ...)
	github.com/caddyserver/caddy/v2@v2.6.2/caddy.go:603 +0x5c5
github.com/caddyserver/caddy/v2.run(0xc0004c04f8?, 0x1)
	github.com/caddyserver/caddy/v2@v2.6.2/caddy.go:525 +0x6a5
github.com/caddyserver/caddy/v2.unsyncedDecodeAndRun({0xc0004ce600, 0x58, 0x60}, 0x1)
	github.com/caddyserver/caddy/v2@v2.6.2/caddy.go:337 +0x145
github.com/caddyserver/caddy/v2.changeConfig({0x26b534a, 0x4}, {0x26c23a4, 0x7}, {0xc000596000, 0xa0, 0x200}, {0x0, 0x0}, 0x0)
	github.com/caddyserver/caddy/v2@v2.6.2/caddy.go:228 +0x79a
github.com/caddyserver/caddy/v2.Load({0xc000596000?, 0x26f0eb7?, 0xc000596000?}, 0xa0?)
	github.com/caddyserver/caddy/v2@v2.6.2/caddy.go:127 +0xaf
github.com/caddyserver/caddy/v2/caddyconfig.adminLoad.handleLoad({}, {0x2a666f0, 0xc0004b4f60}, 0xc0000ae800)
	github.com/caddyserver/caddy/v2@v2.6.2/caddyconfig/load.go:116 +0x525
github.com/caddyserver/caddy/v2.AdminHandlerFunc.ServeHTTP(0x5?, {0x2a666f0?, 0xc0004b4f60?}, 0x1363960?)
	github.com/caddyserver/caddy/v2@v2.6.2/admin.go:1227 +0x2f
github.com/caddyserver/caddy/v2.(*AdminConfig).newAdminHandler.func2.1({0x2a666f0, 0xc0004b4f60}, 0xc0000ae800)
	github.com/caddyserver/caddy/v2@v2.6.2/admin.go:222 +0x87
net/http.HandlerFunc.ServeHTTP(0xc0001c41c0?, {0x2a666f0?, 0xc0004b4f60?}, 0xc0004d1768?)
	net/http/server.go:2109 +0x2f
github.com/caddyserver/caddy/v2.instrumentHandlerCounter.func1({0x2a69840?, 0xc0004da2a0}, 0xc0000ae800)
	github.com/caddyserver/caddy/v2@v2.6.2/metrics.go:46 +0xbc
net/http.HandlerFunc.ServeHTTP(0xc000335b80?, {0x2a69840?, 0xc0004da2a0?}, 0x12e7745?)
	net/http/server.go:2109 +0x2f
net/http.(*ServeMux).ServeHTTP(0x0?, {0x2a69840, 0xc0004da2a0}, 0xc0000ae800)
	net/http/server.go:2487 +0x149
github.com/caddyserver/caddy/v2.adminHandler.serveHTTP({0xc0001c41c0, 0x0, 0x0, {0xc000218908, 0x1, 0x1}, 0x0}, {0x2a69840, 0xc0004da2a0}, 0xc0000ae800)
	github.com/caddyserver/caddy/v2@v2.6.2/admin.go:791 +0x532
github.com/caddyserver/caddy/v2.adminHandler.ServeHTTP({0xc0001c41c0, 0x0, 0x0, {0xc000218908, 0x1, 0x1}, 0x0}, {0x2a69840, 0xc0004da2a0}, 0xc0000ae800)
	github.com/caddyserver/caddy/v2@v2.6.2/admin.go:743 +0x7fe
net/http.serverHandler.ServeHTTP({0x2a64a80?}, {0x2a69840, 0xc0004da2a0}, 0xc0000ae800)
	net/http/server.go:2947 +0x30c
net/http.(*conn).serve(0xc000439a40, {0x2a6b438, 0xc00052a0c0})
	net/http/server.go:1991 +0x607
created by net/http.(*Server).Serve
	net/http/server.go:3102 +0x4db
2023/04/19 18:06:53.710	INFO	admin	stopped previous server	{"address": ":2019"}

3. Caddy version:

v2.6.2 h1:wKoFIxpmOJLGl3QXoo6PNbYvGW4xLEgo32GPBEjWL8o=

4. How I installed and ran Caddy:

  1. Installed via brew, same error in Docker image as well.

a. System environment:

Mac OS Ventura 13.2.1

b. Command:

caddy run to start with the original Caddyfile

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

c. Service/unit/compose file:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

d. My complete Caddy config:

Already provided above

5. Links to relevant resources:

According to API — Caddy Documentation, if the remote url sets the content-type to text/caddyfile, this should work.

Please use the latest, v2.6.4

Got the same error using v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=

2023/04/20 12:41:06.023	INFO	http: panic serving [::1]:50053: runtime error: invalid memory address or nil pointer dereference
goroutine 74 [running]:
net/http.(*conn).serve.func1()
	net/http/server.go:1850 +0xbf
panic({0x231c5a0, 0x35b00c0})
	runtime/panic.go:890 +0x262
github.com/caddyserver/caddy/v2.(*Logging).Logger(0xc00052a840, {0x0?, 0x0?})
	github.com/caddyserver/caddy/v2@v2.6.4/logging.go:202 +0x41
github.com/caddyserver/caddy/v2.Context.Logger({{0x29ff5f0, 0xc00076c4c0}, 0xc00052a810, 0xc0002feaf0, {0x0, 0x0, 0x0}, {0x0, 0x0, 0x0}}, ...)
	github.com/caddyserver/caddy/v2@v2.6.4/context.go:478 +0xa5
github.com/caddyserver/caddy/v2/caddyconfig.HTTPLoader.LoadConfig({{0x0, 0x0}, {0xc0004923e0, 0x20}, 0x0, 0x0, 0x0}, {{0x29ff5f0, 0xc00076c4c0}, 0xc00052a810, ...})
	github.com/caddyserver/caddy/v2@v2.6.4/caddyconfig/httploader.go:116 +0x89f
github.com/caddyserver/caddy/v2.finishSettingUp({{0x29ff5f0, 0xc00076c4c0}, 0xc00052a810, 0xc0002feaf0, {0x0, 0x0, 0x0}, {0x0, 0x0, 0x0}}, ...)
	github.com/caddyserver/caddy/v2@v2.6.4/caddy.go:603 +0x5c5
github.com/caddyserver/caddy/v2.run(0xc000806098?, 0x1)
	github.com/caddyserver/caddy/v2@v2.6.4/caddy.go:525 +0x6a5
github.com/caddyserver/caddy/v2.unsyncedDecodeAndRun({0xc0001162a0, 0x58, 0x60}, 0x1)
	github.com/caddyserver/caddy/v2@v2.6.4/caddy.go:337 +0x145
github.com/caddyserver/caddy/v2.changeConfig({0x254675e, 0x4}, {0x254e4a7, 0x7}, {0xc000310600, 0xa0, 0x200}, {0x0, 0x0}, 0x0)
	github.com/caddyserver/caddy/v2@v2.6.4/caddy.go:228 +0x79a
github.com/caddyserver/caddy/v2.Load({0xc000310600?, 0x2560ba4?, 0xc000310600?}, 0xa0?)
	github.com/caddyserver/caddy/v2@v2.6.4/caddy.go:127 +0xaf
github.com/caddyserver/caddy/v2/caddyconfig.adminLoad.handleLoad({}, {0x29fa730, 0xc000536150}, 0xc00014a100)
	github.com/caddyserver/caddy/v2@v2.6.4/caddyconfig/load.go:116 +0x525
github.com/caddyserver/caddy/v2.AdminHandlerFunc.ServeHTTP(0x5?, {0x29fa730?, 0xc000536150?}, 0x13687c0?)
	github.com/caddyserver/caddy/v2@v2.6.4/admin.go:1243 +0x2f
github.com/caddyserver/caddy/v2.(*AdminConfig).newAdminHandler.func2.1({0x29fa730, 0xc000536150}, 0xc00014a100)
	github.com/caddyserver/caddy/v2@v2.6.4/admin.go:235 +0x87
net/http.HandlerFunc.ServeHTTP(0xc0004c8880?, {0x29fa730?, 0xc000536150?}, 0xc000467768?)
	net/http/server.go:2109 +0x2f
github.com/caddyserver/caddy/v2.instrumentHandlerCounter.func1({0x29fda60?, 0xc0004780e0}, 0xc00014a100)
	github.com/caddyserver/caddy/v2@v2.6.4/metrics.go:46 +0xbc
net/http.HandlerFunc.ServeHTTP(0xc000177e20?, {0x29fda60?, 0xc0004780e0?}, 0x12ec565?)
	net/http/server.go:2109 +0x2f
net/http.(*ServeMux).ServeHTTP(0x0?, {0x29fda60, 0xc0004780e0}, 0xc00014a100)
	net/http/server.go:2487 +0x149
github.com/caddyserver/caddy/v2.adminHandler.serveHTTP({0xc0004c8880, 0x0, 0x0, {0xc000013118, 0x1, 0x1}, 0x0}, {0x29fda60, 0xc0004780e0}, 0xc00014a100)
	github.com/caddyserver/caddy/v2@v2.6.4/admin.go:807 +0x532
github.com/caddyserver/caddy/v2.adminHandler.ServeHTTP({0xc0004c8880, 0x0, 0x0, {0xc000013118, 0x1, 0x1}, 0x0}, {0x29fda60, 0xc0004780e0}, 0xc00014a100)
	github.com/caddyserver/caddy/v2@v2.6.4/admin.go:759 +0x7fe
net/http.serverHandler.ServeHTTP({0x29f8a18?}, {0x29fda60, 0xc0004780e0}, 0xc00014a100)
	net/http/server.go:2947 +0x30c
net/http.(*conn).serve(0xc0001474a0, {0x29ff698, 0xc00052a0c0})
	net/http/server.go:1991 +0x607
created by net/http.(*Server).Serve
	net/http/server.go:3102 +0x4db
2023/04/20 12:41:06.496	INFO	admin	stopped previous server	{"address": ":2019"}

Thanks, I’ll look into this.

Should be fixed in core: Return default logger if no modules loaded · caddyserver/caddy@c6ac350 · GitHub – please feel free to try it :smiley: (CI artifacts will be available soon.)

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