From 078c2ea97a4356ff266563dd6111f7694d44a7fc Mon Sep 17 00:00:00 2001 From: itaru2622 Date: Mon, 21 Oct 2024 07:39:14 +0900 Subject: [PATCH 1/2] feature: configurable liveness check interval, for shutting down if no events are received --- cmd/jetstream/main.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/jetstream/main.go b/cmd/jetstream/main.go index d3f8e60..ed2d6ad 100644 --- a/cmd/jetstream/main.go +++ b/cmd/jetstream/main.go @@ -94,6 +94,12 @@ func main() { Value: -1, EnvVars: []string{"JETSTREAM_OVERRIDE_RELAY_CURSOR"}, }, + &cli.DurationFlag{ + Name: "liveness-ttl", + Usage: "time to restart when no event detected", + Value: 15 * time.Second, + EnvVars: []string{"JETSTREAM_LIVENESS_TTL"}, + }, } app.Action = Jetstream @@ -171,11 +177,11 @@ func Jetstream(cctx *cli.Context) error { // Usually when a critical routine returns an error livenessKill := make(chan struct{}) - // Start a goroutine to manage the liveness checker, shutting down if no events are received for 15 seconds + // Start a goroutine to manage the liveness checker, shutting down if no events are received for liveness-ttl shutdownLivenessChecker := make(chan struct{}) livenessCheckerShutdown := make(chan struct{}) go func() { - ticker := time.NewTicker(15 * time.Second) + ticker := time.NewTicker(cctx.Duration("liveness-ttl")) lastSeq := int64(0) log := log.With("source", "liveness_checker") @@ -188,7 +194,7 @@ func Jetstream(cctx *cli.Context) error { case <-ticker.C: seq, _ := c.Progress.Get() if seq == lastSeq && seq != 0 { - log.Error("no new events in last 15 seconds, shutting down for docker to restart me", "seq", seq) + log.Error("no new events in last "+ cctx.Duration("liveness-ttl").String() +", shutting down for docker to restart me", "seq", seq) close(livenessKill) } else { // Trim the database From 80a8fa372f021fcfacf57284f0d1cd387d2e72a1 Mon Sep 17 00:00:00 2001 From: itaru2622 Date: Mon, 21 Oct 2024 07:41:43 +0900 Subject: [PATCH 2/2] unveil default livness check interval at docker-compose.yaml --- docker-compose.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yaml b/docker-compose.yaml index 729ba84..344483e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -11,3 +11,5 @@ services: - ./data:/data environment: - JETSTREAM_DATA_DIR=/data +# livness check interval to restart when no events are received (default: 15sec) + - JETSTREAM_LIVENESS_TTL=15s