Skip to content

Commit 9c59d70

Browse files
committed
force shutdown upon receiving second os signal
Signed-off-by: sami <sami@appscode.com>
1 parent c16582c commit 9c59d70

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

internal/listener/listener.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strconv"
1212
"sync"
1313
"sync/atomic"
14+
"syscall"
1415
"time"
1516

1617
"kubeops.dev/pgoutbox/apis"
@@ -138,6 +139,16 @@ func (l *Listener) InitHandlers(ctx context.Context) {
138139
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
139140
defer cancel()
140141

142+
// ref: https://github.com/appscode-cloud/cloud-be/blob/79fd250eeb79d47abdd2d38525a0b9b21e1920cf/common/util/signal.go
143+
shutdownHandler := make(chan os.Signal, 2)
144+
signal.Notify(shutdownHandler, os.Interrupt, syscall.SIGTERM)
145+
go func() {
146+
<-shutdownHandler
147+
cancel()
148+
<-shutdownHandler
149+
os.Exit(1) // force exit upon receiving second signal
150+
}()
151+
141152
if err := srv.Shutdown(shutdownCtx); err != nil {
142153
l.log.Error("http server shutdown error", "err", err)
143154
}

0 commit comments

Comments
 (0)