Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 [Bug]: Abort Signal #2982

Closed
3 tasks done
liel-almog opened this issue Apr 23, 2024 · 5 comments
Closed
3 tasks done

馃悰 [Bug]: Abort Signal #2982

liel-almog opened this issue Apr 23, 2024 · 5 comments

Comments

@liel-almog
Copy link

liel-almog commented Apr 23, 2024

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.
Copy link

welcome bot commented Apr 23, 2024

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

@kbiits
Copy link

kbiits commented May 3, 2024

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

@kbiits
Copy link

kbiits commented May 3, 2024

Read this explanation on fasthttp valyala/fasthttp#965

@ReneWerner87
Copy link
Member

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

@liel-almog
Copy link
Author

I must say this is the exact problem I was facing,
The only solution is to not use fasthttp and thus not use Fiber which is a shame.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants