fiber: ๐Ÿ› Memory Leak from Compress middleware

Fiber version v2.3.2 Issue description My fiber server got killed several times due to OOM. Log shows the serverโ€™s memory climbed over time and eventually took 3G ~ 4G before Linux kernel kills it. Just remove the line app.Use(compress.New()) made the memory stable at around 100M.

pprof shows brotli was holding the memory. image

Code snippet

package main

import "github.com/gofiber/fiber/v2"

func main() {
  app := fiber.New()

  // Steps to reproduce
  app.Use(compress.New())

  log.Fatal(app.Listen(":3000"))
}

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

I found this issue valyala/fasthttp#782 and maybe you can try this solution .

@kiyonlin no, thereโ€™s no large file. And Iโ€™m able to reproduce it now with wrk. server.go

func main() {
	app := fiber.New()
	app.Use(compress.New())

	app.Static("/", "./")

	app.Listen(":4000")
}

Put a 1Mb dummy.json in the root, I use this. Start the server and run wrk -H "Accept-Encoding: gzip, br" -c 200 http://localhost:4000/dummy.json

Then you will see the memory go up to 4G: image

When only use Gzip, the memory is around 250M.