samber / slog-fiber

🚨 Fiber middleware for slog logger
https://pkg.go.dev/github.com/samber/slog-fiber
MIT License
57 stars 9 forks source link

fiber use rate limiter panic #4

Closed febelery closed 1 year ago

febelery commented 1 year ago

app := fiber.New(fiber.Config{
  Concurrency:  512 * 1024,
  ErrorHandler: errorx.Handler,
})

app.Use(slogfiber.New(slog.Default().WithGroup("http")))

app.Use(limiter.New(limiter.Config{
  Max:               1,
  Expiration:        2 * time.Second,
  LimiterMiddleware: limiter.SlidingWindow{},
}))

when rate limit occur panic

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x8cd848]

goroutine 59 [running]:
skeleton/cmd/server.NewHttpServer.New.NewWithConfig.func2(0xab6b40?)
        /home/user/go/pkg/mod/github.com/samber/slog-fiber@v1.1.0/middleware.go:79 +0xa68
github.com/gofiber/fiber/v2.(*App).next(0xc0000ba000, 0xc000004300)
        /home/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.49.1/router.go:145 +0x1b2
github.com/gofiber/fiber/v2.(*App).handler(0xc0000ba000, 0x48f80f?)
        /home/user/go/pkg/mod/github.com/gofiber/fiber/v2@v2.49.1/router.go:172 +0x78
github.com/valyala/fasthttp.(*Server).serveConn(0xc0000be000, {0xc6b9b8?, 0xc00012a670})
        /home/user/go/pkg/mod/github.com/valyala/fasthttp@v1.49.0/server.go:2357 +0x11d4
github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc0000360a0, 0xc000154a20)
        /home/user/go/pkg/mod/github.com/valyala/fasthttp@v1.49.0/workerpool.go:224 +0xa4
github.com/valyala/fasthttp.(*workerPool).getCh.func1()
        /home/user/go/pkg/mod/github.com/valyala/fasthttp@v1.49.0/workerpool.go:196 +0x32
created by github.com/valyala/fasthttp.(*workerPool).getCh in goroutine 15
        /home/user/go/pkg/mod/github.com/valyala/fasthttp@v1.49.0/workerpool.go:195 +0x1ab
samber commented 1 year ago

Please update to v1.1.1

We've made a fix yesterday evening.

febelery commented 1 year ago

Ok, fixed