Skip to content

Commit 8899dd6

Browse files
committed
tt: add using channels instead of contexts to handle signals
1 parent ce31327 commit 8899dd6

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

cli/running/running.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/tarantool/tt/cli/process_utils"
2121
"github.com/tarantool/tt/cli/ttlog"
2222
"github.com/tarantool/tt/cli/util"
23-
"golang.org/x/net/context"
2423
"gopkg.in/yaml.v2"
2524
)
2625

@@ -516,18 +515,19 @@ func FillCtx(cliOpts *config.CliOpts, cmdCtx *cmdcontext.CmdCtx,
516515

517516
// Start an Instance.
518517
func Start(cmdCtx *cmdcontext.CmdCtx, run *InstanceCtx) error {
519-
// Register a context, related with a signal handler that
520-
// removes a pid file if interrupt signals were sent before starting
521-
// an instance and watchdog signal handlers.
522-
sigCtx, stop := signal.NotifyContext(context.Background(),
518+
// Register a signal handler that removes a pid file if interrupt
519+
// signals were sent to the process before starting an instance
520+
// and watchdog signal handlers.
521+
signalChan := make(chan os.Signal, 1)
522+
signal.Notify(signalChan,
523523
syscall.SIGINT, syscall.SIGTERM)
524524
if err := process_utils.CreatePIDFile(run.PIDFile); err != nil {
525525
return err
526526
}
527527

528528
defer func() {
529529
cleanup(run)
530-
stop()
530+
signal.Stop(signalChan)
531531
}()
532532

533533
logger := createLogger(run)
@@ -537,9 +537,14 @@ func Start(cmdCtx *cmdcontext.CmdCtx, run *InstanceCtx) error {
537537
// The Done() state of the context means that the process received
538538
// an interrupt signal and there is a need to clean up the resources.
539539
select {
540-
case <-sigCtx.Done():
540+
case <-signalChan:
541541
return nil
542542
default:
543+
// Ignore function unregisters the current signal handler.
544+
// SIGINT and SIGTERM signals will be ignored until the call of
545+
// signal.Reset(), that will be done before the start of
546+
// watchdog's signal handling loop.
547+
signal.Ignore(syscall.SIGINT, syscall.SIGTERM)
543548
wd.Start()
544549
}
545550
return nil

cli/running/watchdog.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ func (wd *Watchdog) Start() {
111111
// startSignalHandling starts signal handling in a separate goroutine.
112112
func (wd *Watchdog) startSignalHandling() {
113113
sigChan := make(chan os.Signal, 1)
114-
// Reset unregisters all previous handlers for interrupt signals.
115-
signal.Reset(syscall.SIGINT,
116-
syscall.SIGTERM, syscall.SIGHUP)
117114
signal.Notify(sigChan)
118115

119116
// Set barrier to synchronize with the main loop when the Instance stops.

0 commit comments

Comments
 (0)