From 9bebafd10e47957f8b67db7095c350db2387479c Mon Sep 17 00:00:00 2001 From: hanabi1224 Date: Thu, 31 Oct 2024 21:21:26 +0800 Subject: [PATCH] fix(f3): auto-restart F3 service on errors (#4957) --- f3-sidecar/ffi_impl.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/f3-sidecar/ffi_impl.go b/f3-sidecar/ffi_impl.go index b687fcf1f556..3ae45d68b9ad 100644 --- a/f3-sidecar/ffi_impl.go +++ b/f3-sidecar/ffi_impl.go @@ -3,6 +3,7 @@ package main import ( "context" "os" + "time" logging "github.com/ipfs/go-log/v2" ) @@ -26,7 +27,17 @@ type f3Impl struct { } func (f3 *f3Impl) run(rpc_endpoint string, jwt string, f3_rpc_endpoint string, initial_power_table string, bootstrap_epoch int64, finality int64, db string, manifest_server string) bool { - err := run(f3.ctx, rpc_endpoint, jwt, f3_rpc_endpoint, initial_power_table, bootstrap_epoch, finality, db, manifest_server) + var err error = nil + const MAX_RETRY int = 5 + nRetry := 0 + for nRetry <= MAX_RETRY { + err = run(f3.ctx, rpc_endpoint, jwt, f3_rpc_endpoint, initial_power_table, bootstrap_epoch, finality, db, manifest_server) + if err != nil { + nRetry += 1 + logger.Errorf("Unexpected F3 failure, retrying(%d) in 10s... error=%s", nRetry, err) + time.Sleep(10 * time.Second) + } + } return err == nil }