Files
podman/pkg/api/server/handler_panic.go
Matt Heon 34166fc004 Bump Go version to v6
Tremendous amount of changes in here, but all should amount to
the same thing: changing Go import paths from v5 to v6.

Also bumped go.mod to github.com/containers/podman/v6 and updated
version to v6.0.0-dev.

Signed-off-by: Matt Heon <mheon@redhat.com>
2025-10-23 11:00:15 -04:00

35 lines
946 B
Go

//go:build !remote
package server
import (
"fmt"
"net/http"
"runtime"
"github.com/containers/podman/v6/pkg/api/handlers/utils"
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"
)
// panicHandler captures panics from endpoint handlers and logs stack trace
func panicHandler() mux.MiddlewareFunc {
return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// http.Server hides panics from handlers, we want to record them and fix the cause
defer func() {
err := recover()
if err != nil {
buf := make([]byte, 1<<20)
n := runtime.Stack(buf, true)
logrus.Warnf("Recovering from API service endpoint handler panic: %v, %s", err, buf[:n])
// Try to inform client things went south... won't work if handler already started writing response body
utils.InternalServerError(w, fmt.Errorf("%v", err))
}
}()
h.ServeHTTP(w, r)
})
}
}