fiber icon indicating copy to clipboard operation
fiber copied to clipboard

🤗 [Question]: Graceful shutdown by enable prefork

Open Shuixiang opened this issue 10 months ago • 6 comments

Question Description

i had follow this,but it not works, so i make my code below

when disable prefork configuration,it works,i got the correct information and response below

Image

when enable prefork configration,it never works,i got no response

Image

How can i shutdown the app graceful, and get the correct response.

Code Snippet (optional)

package main

import (
	"context"
	"os"
	"os/signal"
	"time"

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

func main() {
	app := fiber.New(fiber.Config{
		AppName: "Fiber Great",
		Prefork: true,
	})

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

	go func() {
		if err := app.Listen(":3000"); err != nil {
			log.Fatal(err)
		}
	}()

	quit := make(chan os.Signal, 1)
	signal.Notify(quit, os.Interrupt)
	<-quit

	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()

	log.Info("Shutdown Server Beginning...")
	_ = app.ShutdownWithContext(ctx)
	log.Info("Running cleanup tasks...")
	log.Info("Exited Server...")
}

Checklist:

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

Shuixiang avatar Apr 08 '25 09:04 Shuixiang

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

welcome[bot] avatar Apr 08 '25 09:04 welcome[bot]

@codemicro can you support here

ReneWerner87 avatar Apr 08 '25 10:04 ReneWerner87

I don't believe so - that's an example I wrote 5 years ago and it looks like there are some weird mechanics that are going on with prefork that I don't quite understand (and unfortunately don't have the time to look into at the moment). Apologies!

codemicro avatar Apr 08 '25 12:04 codemicro

@Shuixiang Hi, I tried to run this code locally and neither setting Prefork: true nor Prefork: false reproduced what you said. Can you give more information about this? Like your OS model, version, etc.

Prefork: false

Image

Prefork: true

Image

Image

JIeJaitt avatar Apr 09 '25 03:04 JIeJaitt

@JIeJaitt
on Windows 11 fiber version is 2.25.5 go version is 1.23.4 And the key point is no response to browser while enable prefork, i wanna get response to browser before server is gone, but it is not work while enable prefork Maybe cause of the operating system is windows?

Shuixiang avatar Apr 15 '25 06:04 Shuixiang

@JIeJaitt on Windows 11 fiber version is 2.25.5 go version is 1.23.4 And the key point is no response to browser while enable prefork, i wanna get response to browser before server is gone, but it is not work while enable prefork Maybe cause of the operating system is windows?

For graceful shutdown, Linux does not work either.

nl30du avatar Apr 15 '25 11:04 nl30du