I use Caddy build with some custom modules. And today I ran into a problem: panic: net/http: abort Handler
. There is no stack trace.
{"level":"info","ts":1702043658.836168,"msg":"using provided configuration","config_file":"/etc/caddy/conf-json/Caddyfile.json","config_adapter":""}
{"level":"info","ts":1702043658.8435194,"msg":"redirected default logger","from":"stderr","to":"/var/lib/caddy-logs/all.log"}
{"level":"info","ts":1702043659.155859,"msg":"failed to sufficiently increase receive buffer size (was: 208 kiB, wanted: 2048 kiB, got: 416 kiB). See https://github.com/quic-go/quic-go/wiki/UDP-Buffer-Sizes for details."}
panic: net/http: abort Handler
I use Caddy 2.7.6 in Docker 24.0.7 on Ubuntu 22.04.3 with kernel 5.15.0-89-generic.
Where should I write recover
to catch all possible panics?
Mohammed90
(Mohammed Al Sahaf)
December 8, 2023, 3:14pm
2
Please fill out the template per the forum rules to allow to give valuable guidance. The information in the post are not enough.
I just want to ask is there single endpoint to catch all panics from any module?
Modules should never produce panics. If they use code which can panic, they should themselves recover
before returning and return an error instead.
Again, please fill out the help topic template, we can’t help further without full context of what you’re trying.
2 Likes
matt
(Matt Holt)
December 9, 2023, 4:06am
5
In general, every goroutine would need a recover
to catch panics. Since modules all execute in different places and different goroutines like HTTP requests it can be tricky.
(Besides, recovering panics is also not always the right solution.)
1 Like
The problem is linked with this change: http/2 connection is not aborted properly if underlying connection is aborted · Issue #5951 · caddyserver/caddy · GitHub
I have such code in a custom component, which runs before reverseproxy:
go func() {
...
err := next.ServeHTTP(responseWriter, req)
...
}()
Now I recovered panic in this goroutine and it is OK.
I think it’s wrong to run next.SeveHTTP
inside a goroutine. Why are you doing that at all?
For background cache updating
You should be awaiting a channel on the main request goroutine if you have async work to do. You should not continue the middleware chain in a new goroutine.
3 Likes
system
(system)
Closed
January 10, 2024, 1:07pm
10
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.