feat: implements fiber panic recovery

Fiber includes a built-in panic recovery middleware that catches panics in route handlers and middlewares, preventing the server from crashing and allowing it to recover. Alongside this, a stack trace handler has been implemented to store system panics in the context locals (stack).

Both the S3 API server and the Admin server use a global error handler to catch unexpected exceptions and recovered panics. The middleware’s logic is to log the panic or internal error and return an S3-style internal server error response.

Additionally, dedicated **Panic** and **InternalError** loggers have been added to the `s3api` debug logger to record system panics and internal errors in the console.
This commit is contained in:
niksis02
2025-09-23 22:19:05 +04:00
parent dac2460eb3
commit caa7ca0f90
7 changed files with 107 additions and 88 deletions

View File

@@ -18,7 +18,6 @@ import (
"encoding/xml"
"fmt"
"net/http"
"os"
"github.com/gofiber/fiber/v2"
"github.com/versity/versitygw/auth"
@@ -201,7 +200,7 @@ func ProcessController(ctx *fiber.Ctx, controller Controller, s3action string, s
return ctx.Send(s3err.GetAPIErrorResponse(serr, "", "", ""))
}
fmt.Fprintf(os.Stderr, "Internal Error, %v\n", err)
debuglogger.InernalError(err)
ctx.Status(http.StatusInternalServerError)
// If the error is not 's3err.APIError' return 'InternalError'