🤗 [Question]: Graceful shutdown by enable prefork
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
when enable prefork configration,it never works,i got no response
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.
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
@codemicro can you support here
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!
@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
Prefork: true
@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?
@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.