aboutsummaryrefslogtreecommitdiff
path: root/cmd/mobius-hotline-server
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2026-07-09 18:54:04 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2026-07-09 18:54:04 -0700
commitae44fb222ec73cae8441f5a5d9a21f8585fe587f (patch)
tree155ea4b83850345cefc4924d71f3922b988dd304 /cmd/mobius-hotline-server
parente4eb0c07010a32db3cf68083b2d63f9ceb21e009 (diff)
Send a goodbye message to clients on signal-initiated shutdown
SIGTERM and SIGINT canceled the server context directly, so clients were force-closed without the TranDisconnectMsg broadcast that the API shutdown endpoint sends. The signal handler now calls Server.Shutdown with a goodbye message, giving both shutdown paths the same behavior: broadcast, a brief flush window, then force-close and drain. Default signal handling is restored before the graceful shutdown begins, so a second signal still kills the process immediately rather than waiting out the flush window.
Diffstat (limited to 'cmd/mobius-hotline-server')
-rw-r--r--cmd/mobius-hotline-server/main.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/cmd/mobius-hotline-server/main.go b/cmd/mobius-hotline-server/main.go
index 52099ad..bc332f0 100644
--- a/cmd/mobius-hotline-server/main.go
+++ b/cmd/mobius-hotline-server/main.go
@@ -35,6 +35,7 @@ var (
func main() {
ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT, os.Interrupt)
@@ -255,9 +256,14 @@ func main() {
reloadFunc()
default:
- // Canceling the context stops ListenAndServe, which unblocks main for a clean exit.
+ // Restore default signal handling first, so a second signal kills the process
+ // immediately instead of waiting out the graceful shutdown.
signal.Stop(sigChan)
- cancel()
+
+ // Broadcast a goodbye message to connected clients, then stop ListenAndServe,
+ // which unblocks main for a clean exit. Shutdown waits a few seconds so client
+ // writers can flush the message before connections are force-closed.
+ srv.Shutdown([]byte("Server is shutting down."))
}
}