Skip to content

Commit 9886a5a

Browse files
committed
OS signal handler will exit on context cancellation
1 parent cd831c4 commit 9886a5a

2 files changed

Lines changed: 20 additions & 22 deletions

File tree

relayer/main/main.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -361,20 +361,19 @@ func main() {
361361
}
362362

363363
// Handle os signal
364-
errGroup.Go(func() error {
364+
go func() {
365365
sigChan := make(chan os.Signal, 1)
366366
signal.Notify(sigChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
367367

368-
sig := <-sigChan
369-
logger.Info("Receive os signal", zap.Stringer("signal", sig))
370-
371-
// Cancel the parent context
372-
// This will cascade to errgroup context
373-
cancel()
374-
375-
// No error for graceful shutdown
376-
return nil
377-
})
368+
select {
369+
case sig := <-sigChan:
370+
logger.Info("Received os signal", zap.Stringer("signal", sig))
371+
// Cancel the parent context
372+
// This will cascade to errgroup context
373+
cancel()
374+
case <-ctx.Done():
375+
}
376+
}()
378377

379378
logger.Info("Initialization complete")
380379
if err := errGroup.Wait(); err != nil {

signature-aggregator/main/main.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,19 @@ func main() {
203203
})
204204

205205
// Handle os signal
206-
errGroup.Go(func() error {
206+
go func() {
207207
sigChan := make(chan os.Signal, 1)
208208
signal.Notify(sigChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
209209

210-
sig := <-sigChan
211-
logger.Info("Receive os signal", zap.Stringer("signal", sig))
212-
213-
// Cancel the parent context
214-
// This will cascade to errgroup context
215-
cancel()
216-
217-
// No error for graceful shutdown
218-
return nil
219-
})
210+
select {
211+
case sig := <-sigChan:
212+
logger.Info("Received os signal", zap.Stringer("signal", sig))
213+
// Cancel the parent context
214+
// This will cascade to errgroup context
215+
cancel()
216+
case <-ctx.Done():
217+
}
218+
}()
220219

221220
logger.Info("Initialization complete")
222221

0 commit comments

Comments
 (0)