gofiber / fiber

⚑️ Express inspired web framework written in Go

Home Page:https://gofiber.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ› [Bug]: Abort Signal

liel-almog opened this issue Β· comments

Bug Description

I have an application, a part of the is a long process HTTP request.
For that I give the users the option to abort the request with the help of the AbortContoller in JavaScript.
The problem is that the fiber.Ctx.Context().Done() does not end when the abort signal is being transmitteed

How to Reproduce

Steps to reproduce the behavior:
A simple app would be enough.

app.Get("/", func(c *fiber.Ctx) error {

		ctx := c.Context()
		log.Println("Handler started")
		defer log.Println("Handler ended")

		select {
		case <-time.After(5 * time.Second):
			log.Println("Completed processing")
		case <-ctx.Done():
			err := ctx.Err()
			log.Printf("Handler aborted: %v", err)
		}

		return nil
	})
const controller = new AbortController();
const signal = controller.signal;

fetch('http://localhost:5000/', { signal })
    .then(response => response.text())
    .then(data => console.log(data))
    .catch(error => console.error('Fetch aborted', error));

// Abort the request after 2 seconds
setTimeout(() => {
    controller.abort();
}, 2000);

Expected Behavior

I would have expected that when the user use the Abort Signal, the case of ctx.Done() would fire up as it happening in the standard library

Fiber Version

2.54.2

Code Snippet (optional)

package main

import "github.com/gofiber/fiber/v3"
import "log"

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

  // Steps to reproduce

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

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.

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

fiber.Ctx.Context returned *fasthttp.RequestCtx, so the issue should be in fasthttp not in fiber.

Read this explanation on fasthttp valyala/fasthttp#965

commented

@liel-almog is that enough of an explanation for you?