Skip to content

Conversation

@joga84
Copy link
Contributor

@joga84 joga84 commented Aug 5, 2025

getConfig checks cfg.certCache so cfg can never be nil inside of getConfig or it can crash with:
invalid memory address or nil pointer dereference

getConfig checks cfg.certCache so cfg can never be nil inside of
getConfig or it can crash with:
 invalid memory address or nil pointer dereference
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, nice find. This is probably the result of a refactor where the call to GetConfigForCert() was wrapped by getConfig().

Did you happen to encounter this panic? Or did you just notice it with some inspection/tooling?

@mholt mholt merged commit 621b7e9 into caddyserver:master Aug 5, 2025
6 checks passed
@joga84
Copy link
Contributor Author

joga84 commented Aug 5, 2025

Did you happen to encounter this panic? Or did you just notice it with some inspection/tooling?

This was triggering a panic once a week or so on a system with many domains. Hope to now figure out why the config ends up nil in the first place:

{
    "level":"error",
    "ts":1234560000.1111111,
    "logger":"tls.cache.maintenance",
    "msg":"panic",
    "cache":"0xc0004c0e00",
    "error":"runtime error: invalid memory address or nil pointer dereference","stack":"goroutine 66 [running]:
                github.com/caddyserver/certmagic.(*Cache).maintainAssets.func1()
                    github.com/caddyserver/[email protected]/maintain.go:50 +0x85
                panic({0x17a0d80?, 0x2bbd170?})
                    runtime/panic.go:792 +0x132
                github.com/caddyserver/certmagic.(*Cache).getConfig(_, {{{0xc08bbb9dd0, 0x2, 0x2}, {0x192fae0, 0xc0900c23c0}, {0x0, 0x0, 0x0}, {0x0, ...}, ...}, ...})
                    github.com/caddyserver/[email protected]/cache.go:368 +0xbe
                github.com/caddyserver/certmagic.(*Cache).RenewManagedCertificates(0xc0004c0e00, {0x1ee11f0, 0xc00061e000})
                    github.com/caddyserver/[email protected]/maintain.go:121 +0x325
                github.com/caddyserver/certmagic.(*Cache).maintainAssets(0xc0004c0e00, 0x0)
                    github.com/caddyserver/[email protected]/maintain.go:71 +0x348
                created by github.com/caddyserver/certmagic.NewCache in goroutine 1
                    github.com/caddyserver/[email protected]/cache.go:110 +0x185
           "
}

@joga84 joga84 deleted the cfg-nil branch August 5, 2025 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants