cache-handler: Panic if abort directive is used
/etc/caddy/Caddyfile:
{
order cache before rewrite
cache
}
:80 {
cache
abort
}
Start caddy, then do curl http://127.0.0.1. Result: Caddy dies.
Feb 13 12:40:18 desrv systemd[1]: Started Caddy.
Feb 13 12:40:18 desrv caddy[4509]: {"level":"info","ts":1676320818.3576553,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc00057b5e0"}
Feb 13 12:40:18 desrv caddy[4509]: {"level":"info","ts":1676320818.3577983,"logger":"tls","msg":"cleaning storage unit","description":"FileStorage:/var/lib/caddy/.local/share/caddy"}
Feb 13 12:40:18 desrv caddy[4509]: {"level":"info","ts":1676320818.3579395,"logger":"tls","msg":"finished cleaning storage units"}
Feb 13 12:40:18 desrv caddy[4509]: {"level":"info","ts":1676320818.3581178,"msg":"serving initial configuration"}
Feb 13 12:40:43 desrv caddy[4509]: panic: net/http: abort Handler
Feb 13 12:40:43 desrv caddy[4509]: goroutine 50 [running]:
Feb 13 12:40:43 desrv caddy[4509]: github.com/caddyserver/caddy/v2/modules/caddyhttp.StaticResponse.ServeHTTP({{0x0, 0x0}, 0x0, {0x0, 0x0}, 0x0, 0x1}, {0x24f43a0?, 0xc0001f6780?}, 0xc0000b8300, ...)
Feb 13 12:40:43 desrv caddy[4509]: github.com/caddyserver/caddy/v2@v2.6.3/modules/caddyhttp/staticresp.go:184 +0xa38
Feb 13 12:40:43 desrv caddy[4509]: github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1({0x24f43a0?, 0xc0001f6780?}, 0xc0006f0070?)
Feb 13 12:40:43 desrv caddy[4509]: github.com/caddyserver/caddy/v2@v2.6.3/modules/caddyhttp/routes.go:290 +0x42
Feb 13 12:40:43 desrv caddy[4509]: github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0x4487b9?, {0x24f43a0?, 0xc0001f6780?}, 0xffffffffffffffff?)
Feb 13 12:40:43 desrv caddy[4509]: github.com/caddyserver/caddy/v2@v2.6.3/modules/caddyhttp/caddyhttp.go:58 +0x2f
Feb 13 12:40:43 desrv caddy[4509]: github.com/caddyserver/cache-handler.(*SouinCaddyPlugin).ServeHTTP.func1({0x0?, 0x185f960?}, 0xc0006f0070?)
Feb 13 12:40:43 desrv caddy[4509]: github.com/caddyserver/cache-handler@v0.4.0/httpcache.go:129 +0x62
Feb 13 12:40:43 desrv caddy[4509]: github.com/darkweak/souin/plugins.DefaultSouinPluginCallback.func2({0x24f43a0?, 0xc0001f6780?}, 0xf?)
Feb 13 12:40:43 desrv caddy[4509]: github.com/darkweak/souin@v1.6.27/plugins/base.go:210 +0x7a
Feb 13 12:40:43 desrv caddy[4509]: created by github.com/darkweak/souin/plugins.DefaultSouinPluginCallback
Feb 13 12:40:43 desrv caddy[4509]: github.com/darkweak/souin@v1.6.27/plugins/base.go:206 +0x81b
Feb 13 12:40:43 desrv systemd[1]: caddy.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Feb 13 12:40:43 desrv systemd[1]: caddy.service: Failed with result 'exit-code'.
$ /usr/bin/caddy version
v2.6.3 h1:QRVBNIqfpqZ1eJacY44I6eUC1OcxQ8D04EKImzpj7S8=
Built about 15 minutes ago with xcaddy build --with github.com/caddyserver/cache-handler
This is a minimal repro. I have a service that only approved IPs are able to access, otherwise Caddy aborts the request, and when I hit it from an unapproved IP after adding caching it killed Caddy.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 20 (2 by maintainers)
It appears to be working, I can’t find any further issue. Thanks!
@AlyoshaVasilieva Can you try with
xcaddy build --with github.com/darkweak/souin@f05fcc6808b9ba8cc61833b329b0b2b4697a2ad7 --with github.com/darkweak/souin/plugins/caddy@f05fcc6808b9ba8cc61833b329b0b2b4697a2ad7?I’ll have a look at that and try to fix this weird behavior. I will add some e2e test cases to ensure redis works well.
It no longer panics! However, when trying to use redis requests hang forever.
I’ve set all those timeouts in an attempt to make it timeout and issue an HTTP error, but it doesn’t:
I’m not actually sure I’ve set it up correctly, but I’m not getting any error messages.
After attempting to enable logging*, this is all I see in the logs:
* caddyfile:
Well, it’s a different issue now, the original one seems solved. This is a huge improvement over panicking, so thank you!
It’s now available using
xcaddy build --with github.com/darkweak/souin/plugins/caddyThe release is currently running 🤞
Correct - but more specifically,
go getdoes not respectreplace.I think
xcaddydoesn’t fetch packages respecting the replace directive. I think you’ll have to fetch the repository, go to thefeat/chore/refactoring-to-middleware-philosophybranch and run the xcaddy build in thesouin/plugins/caddydirectory.I’ll try to release that asap to avoid these build constaints.
It seems the next minor version I’m working on patch that behavior and prevent the panic (https://github.com/darkweak/souin/compare/master...feat/chore/refactoring-to-middleware-philosophy) and I plan to release that on the next week. Can you wait for that?
Hello @AlyoshaVasilieva thanks for this report, I’ll try to fix that. Thank you for the minimal reproductible example.