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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [Bug]: "ShutdownWithTimeout" & "ShutdownTimeout" not respected #3370

Open
3 tasks done
the-hotmann opened this issue Mar 25, 2025 · 0 comments
Open
3 tasks done

Comments

@the-hotmann
Copy link
Contributor

the-hotmann commented Mar 25, 2025

Bug Description

I created a dummy function, that just offers a 10GB file as download and send it the stop signal (CRTL + C) after starting the download.
Even though I started the server with ShutdownTimeout=10 * time.Second and stopped him with app.ShutdownWithTimeout(10 * time.Second) the app shut down immediately and did not wait the configured time.

How to Reproduce

  1. dd if=/dev/urandom of=/tmp/large_files/large_file.bin bs=1M count=10240 status=progress

  2. CONFIG

// Pfad zur großen Datei
const largeFilePath = "/tmp/large_files/large_file.bin"

// HandleLargeFileStream streamt eine echte 10GB Datei
// Dies hält die Verbindung für eine längere Zeit offen, abhängig von der Downloadgeschwindigkeit
func HandleLargeFileStream(c fiber.Ctx) error {
	// Datei öffnen
	file, err := os.Open(largeFilePath)
	if err != nil {
		return c.Status(fiber.StatusInternalServerError).SendString(fmt.Sprintf("Fehler beim Öffnen der Datei: %v", err))
	}
	defer file.Close()

	// Dateigröße ermitteln
	fileInfo, err := file.Stat()
	if err != nil {
		return c.Status(fiber.StatusInternalServerError).SendString(fmt.Sprintf("Fehler beim Abrufen der Dateigröße: %v", err))
	}
	fileSize := fileInfo.Size()

	// Header setzen
	c.Set("Content-Type", "application/octet-stream")
	c.Set("Content-Disposition", "attachment; filename=\"large_file.bin\"")
	c.Set("Content-Length", fmt.Sprintf("%d", fileSize))

	c.SendFile(largeFilePath)
	return nil
}
// Fiber Listen configuration
fiberConfig := fiber.ListenConfig{
	ShutdownTimeout: 10 * time.Second,
}

Set up this Signal-Trap:

// Set up graceful shutdown
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
go func() {
	<-c
	_ = app.ShutdownWithTimeout(cfg.Server.ShutdownTimeout)
}()

Expected Behavior

I was expecting it to close all listeners but to respect ALL currently active connections (untill the timeout). But this did not happen, the app shut down immediately.

Fiber Version

v3.0.0-beta.4

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

1 participant