Graceful shutdown in Fiber
February 12, 2026 ยท View on GitHub
fiberRecipes/graceful-shutdown on graceful-shutdown (f0834df) [?] via ๐น v1.15.2 took 4s
โฏ go run graceful-shutdown
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Fiber v3.0.0 โ
โ http://127.0.0.1:3000 โ
โ โ
โ Handlers ............. 2 Threads ............. 8 โ
โ Prefork ....... Disabled PID .............. 2540 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
^CGracefully shutting down...
Running cleanup tasks...
This shows how to implement a graceful shutdown with Fiber and the os/signal package.
Explanation
This example relies on the use of channels, a data type in Go that allows you to send and receive data to/from specific places in an application (read more about them here).
A channel is created, and registered with signal.Notify so that when the program receives an interrupt (for example, when CTRL+C is pressed), a notification is sent to the channel. Once this is received, app.Shutdown is called to close all active connections and return from app.Listen. After this point, cleanup functions can be run and the program eventually quits.