Skip to content

🤗 [Question]: Graceful shutdown by enable prefork #3396

@Shuixiang

Description

@Shuixiang

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:

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions