Uploaded June 2026 | Updated November 2026, 3 days ago
Welcome to our Tebeka Shorts series, episode 58! -- In this video, Miki demonstrates how to properly handle OS signals in Go to ensure your web servers shut down gracefully.
Have you ever hit Ctrl+C to stop a Go web server, only to realize your defer cleanup code—like logging, publishing metrics, or deleting a process ID file—never actually ran? This happens because the operating system sends an interrupt signal that terminates the process immediately if it isn't explicitly caught by your application.
In this quick tutorial, you will learn:
- The Problem: Why a basic Go web server terminates right in the middle of execution when receiving a Ctrl+C interrupt
- Key OS Signals: The difference between SIGINT (an interrupt signal from Ctrl+C) and SIGTERM (a termination signal from a kill command)
- The Solution: How to use the golang.org/x/sys/unix package to intercept OS signals rather than relying on default system behaviors
- Implementation: Step-by-step instructions on setting up a buffered signal channel with signal.Notify, running your server in a goroutine, and using a select statement to listen for either incoming signals or server errors
- Graceful Shutdown: How to implement a timeout context (e.g., 3 seconds) to give your server enough time to finish its work and perform a clean shutdown before exiting
By running the web server within a goroutine, developers can use a select statement to wait for signals and initiate a graceful shutdown. This approach ensures that processes like logging metrics or deleting temporary files are completed before the program exits.
----
Comment below or tweet us on twitter & let us know your thoughts, we want to hear from you! ~ If you found this video helpful, hit that like button & subscribe for more content like this.
----
Access our online courses → ardanlabs.com/education
Attending a live training → ardanlabs.com/live-training-events
Other Links:
Website: ardanlabs.com
Github: github.com/ardanlabs
X: twitter.com/ardanlabs
LinkedIn: linkedin.com/ardanlabs
#golang #goprogramming #GracefulShutdown #SignalHandling #OSSignals #sigint #SIGTERM #GoTutorial
Welcome to our Tebeka Shorts series, episode 58! -- In this video, Miki demonstrates how to properly handle OS signals in Go to ensure your web servers shut down gracefully.
Have you ever hit Ctrl+C to stop a Go web server, only to realize your defer cleanup code—like logging, publishing metrics, or deleting a process ID file—never actually ran? This happens because the operating system sends an interrupt signal that terminates the process immediately if it isn't explicitly caught by your application.
In this quick tutorial, you will learn:
- The Problem: Why a basic Go web server terminates right in the middle of execution when receiving a Ctrl+C interrupt
- Key OS Signals: The difference between SIGINT (an interrupt signal from Ctrl+C) and SIGTERM (a termination signal from a kill command)
- The Solution: How to use the golang.org/x/sys/unix package to intercept OS signals rather than relying on default system behaviors
- Implementation: Step-by-step instructions on setting up a buffered signal channel with signal.Notify, running your server in a goroutine, and using a select statement to listen for either incoming signals or server errors
- Graceful Shutdown: How to implement a timeout context (e.g., 3 seconds) to give your server enough time to finish its work and perform a clean shutdown before exiting
By running the web server within a goroutine, developers can use a select statement to wait for signals and initiate a graceful shutdown. This approach ensures that processes like logging metrics or deleting temporary files are completed before the program exits.
----
Comment below or tweet us on twitter & let us know your thoughts, we want to hear from you! ~ If you found this video helpful, hit that like button & subscribe for more content like this.
----
Access our online courses → ardanlabs.com/education
Attending a live training → ardanlabs.com/live-training-events
Other Links:
Website: ardanlabs.com
Github: github.com/ardanlabs
X: twitter.com/ardanlabs
LinkedIn: linkedin.com/ardanlabs
#golang #goprogramming #GracefulShutdown #SignalHandling #OSSignals #sigint #SIGTERM #GoTutorial










