Skip to content

Commit

Permalink
Exit process if config reloading gets stuck
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 686477043
  • Loading branch information
torsm authored and copybara-github committed Oct 16, 2024
1 parent ad7fc07 commit 11c029a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/fleetspeak_client/fleetspeak_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"os"
"time"

log "github.com/golang/glog"
"google.golang.org/protobuf/encoding/prototext"
Expand All @@ -23,6 +24,8 @@ import (
gpb "github.com/google/fleetspeak/fleetspeak/src/client/generic/proto/fleetspeak_client_generic"
)

const stopTimeout = time.Minute

var configFile = flag.String("config", "", "Client configuration file, required.")

func innerMain(ctx context.Context, cfgReloadSignals <-chan os.Signal) error {
Expand All @@ -37,9 +40,13 @@ func innerMain(ctx context.Context, cfgReloadSignals <-chan os.Signal) error {
// We implement config reloading by tearing down the client and creating a
// new one.
log.Info("Config reload requested")
time.AfterFunc(stopTimeout, func() {
entry.ExitUngracefully(fmt.Errorf("client did not stop within %s", stopTimeout))
})
cl.Stop()
continue
case <-ctx.Done():
// A timeout for process termination is handled higher up.
cl.Stop()
return nil
}
Expand Down

0 comments on commit 11c029a

Please sign in to comment.