File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments