gofiber / fiber

⚡️ Express inspired web framework written in Go
https://gofiber.io
MIT License
33.2k stars 1.64k forks source link

🤗 [Question]: Fiber config WriteTimeout and ReadTimeout not working #2702

Closed fluoz closed 10 months ago

fluoz commented 10 months ago

Question Description

How WriteTimeout and ReadTimeout works and how i want to test it?

Code Snippet (optional)

package main

import (
    "log"
    "time"

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

func main() {

    app := fiber.New(fiber.Config{
        ReadTimeout:  1 * time.Second,
        WriteTimeout: 1 * time.Second,
    })

    app.Get("/ping", func(c *fiber.Ctx) error {
        time.Sleep(2 * time.Second)
        return c.SendString("hello")
    })

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

Checklist:

welcome[bot] commented 10 months ago

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

ReneWerner87 commented 10 months ago

Pls check the documentation https://docs.gofiber.io/api/fiber

These 2 settings have nothing to do with the timeout in your handler.

The read timeout is the timeout that exists when the request is read and the write timeout is the timeout for writing the response. These settings are in the unittests of our package and or the underlying fasthttp framework. You are probably looking for a way to give your handler a timeout for execution, for that look at this https://docs.gofiber.io/api/middleware/timeout

ReneWerner87 commented 10 months ago

@fluoz any other question to this?

ReneWerner87 commented 10 months ago

if you have any questions, just reopen