service: plumb contexts to all (most) threads (#7363)

This continues the push of plumbing contexts through tendermint. I
attempted to find all goroutines in the production code (non-test) and
made sure that these threads would exit when their contexts were
canceled, and I believe this PR does that.
This commit is contained in:
Sam Kleinman
2021-12-02 21:38:38 +00:00
committed by GitHub
parent b3be1d7d7a
commit 8a991e288c
64 changed files with 964 additions and 727 deletions
+4 -1
View File
@@ -50,6 +50,9 @@ func main() {
)
flag.Parse()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger.Info(
"Starting private validator",
"addr", *addr,
@@ -131,7 +134,7 @@ func main() {
}
// Stop upon receiving SIGTERM or CTRL-C.
tmos.TrapSignal(logger, func() {
tmos.TrapSignal(ctx, logger, func() {
logger.Debug("SignerServer: calling Close")
if *prometheusAddr != "" {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
+1 -10
View File
@@ -1,8 +1,6 @@
package commands
import (
"context"
"os"
"os/signal"
"syscall"
@@ -40,16 +38,9 @@ func init() {
}
func runInspect(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithCancel(cmd.Context())
ctx, cancel := signal.NotifyContext(cmd.Context(), syscall.SIGTERM, syscall.SIGINT)
defer cancel()
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGTERM, syscall.SIGINT)
go func() {
<-c
cancel()
}()
ins, err := inspect.NewFromConfig(logger, config)
if err != nil {
return err
+1 -1
View File
@@ -189,7 +189,7 @@ func runProxy(cmd *cobra.Command, args []string) error {
}
// Stop upon receiving SIGTERM or CTRL-C.
tmos.TrapSignal(logger, func() {
tmos.TrapSignal(cmd.Context(), logger, func() {
p.Listener.Close()
})