From 5077b2e4bf327ac87abdf7bc552624948f8685ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=C3=A1n=20C=20McCord?= Date: Sun, 1 Oct 2023 20:48:55 -0400 Subject: [PATCH] handle shutdown signal --- cmd/inbound/inbound.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/inbound/inbound.go b/cmd/inbound/inbound.go index 6cfe6e2..7cce17d 100644 --- a/cmd/inbound/inbound.go +++ b/cmd/inbound/inbound.go @@ -108,6 +108,8 @@ func main() { s.MaxRecipients = 10 s.AuthDisabled = true + defer s.Close() // nolint:errcheck + log.Info("starting health service") go runHealthService(cm) @@ -126,7 +128,17 @@ func main() { }() } - log.Fatal("server exited", zap.Error(s.ListenAndServe())) + go func() { + defer cancel() + + if err := s.ListenAndServe(); err != nil { + log.Error("listener failed", zap.Error(err)) + } + }() + + <-ctx.Done() + + log.Info("exiting") } func runHealthService(cm *localtls.CertManager) {