Skip to content

Memory leak under Slowloris attack #2037

@ghostdevxd

Description

@ghostdevxd

Version info:

  • Go: go1.23.10 windows/amd64
  • Fasthttp: v1.63.0

What happened

When running a simple fasthttp server and testing it using a Slowloris attack (via goloris), the memory usage of the fasthttp process increases rapidly and does not decrease for many minutes even after the attack ends.

Code

package main

import (
	"github.com/valyala/fasthttp"
)

func main() {
	requestHandler := func(ctx *fasthttp.RequestCtx) {
		switch string(ctx.Path()) {
		case "/":
			ctx.SetStatusCode(fasthttp.StatusOK)
			ctx.SetBody([]byte("Hello, World!"))
		default:
			ctx.SetStatusCode(fasthttp.StatusNotFound)
			ctx.SetBody([]byte(""))
		}
	}

	if err := fasthttp.ListenAndServe(":3000", requestHandler); err != nil {
		panic("Server Error: " + err.Error())
	}
}

Task Manager

Image

PPROF

flat flat% sum% cum cum% Function
231.30MB 98.93% 98.93% 231.30MB 98.93% github.com/valyala/fasthttp.appendBodyFixedSize
0 0% 98.93% 231.30MB 98.93% github.com/valyala/fasthttp.(*Request).ContinueReadBody
0 0% 98.93% 231.30MB 98.93% github.com/valyala/fasthttp.(*Request).ReadBody
0 0% 98.93% 231.30MB 98.93% github.com/valyala/fasthttp.(*Request).readLimitBody
0 0% 98.93% 232.81MB 99.57% github.com/valyala/fasthttp.(*Server).serveConn
0 0% 98.93% 232.81MB 99.57% github.com/valyala/fasthttp.(*workerPool).getCh.func1
0 0% 98.93% 232.81MB 99.57% github.com/valyala/fasthttp.(*workerPool).workerFunc
0 0% 98.93% 231.30MB 98.93% github.com/valyala/fasthttp.readBody

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions