Skip to content

Commit 5fdb723

Browse files
JuArceMauroToscano
andauthored
hotfix(operator): retry logic for batches download (#2030)
Co-authored-by: MauroFab <[email protected]> Co-authored-by: Mauro Toscano <[email protected]>
1 parent 50d74e0 commit 5fdb723

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

operator/pkg/operator.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
"encoding/hex"
77
"encoding/json"
88
"fmt"
9-
rapidsnark_types "github.com/iden3/go-rapidsnark/types"
10-
"github.com/iden3/go-rapidsnark/verifier"
119
"log"
1210
"math/big"
1311
"net/http"
@@ -16,6 +14,9 @@ import (
1614
"sync"
1715
"time"
1816

17+
rapidsnark_types "github.com/iden3/go-rapidsnark/types"
18+
"github.com/iden3/go-rapidsnark/verifier"
19+
1920
"github.com/ethereum/go-ethereum/crypto"
2021
"github.com/urfave/cli/v2"
2122
"github.com/yetanotherco/aligned_layer/operator/risc_zero"
@@ -64,8 +65,10 @@ type Operator struct {
6465
}
6566

6667
const (
67-
BatchDownloadTimeout = 1 * time.Minute
68-
BatchDownloadMaxRetries = 3
68+
// This time out will even kill the retries, so it should be enough
69+
// for them to be completed in most cases
70+
BatchDownloadTimeout = 3 * time.Minute
71+
BatchDownloadMaxRetries = 4
6972
BatchDownloadRetryDelay = 5 * time.Second
7073
UnverifiedBatchOffset = 100
7174
)

operator/pkg/s3.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ func (o *Operator) getBatchFromDataService(ctx context.Context, batchURL string,
1818
var err error
1919
var req *http.Request
2020

21+
// Create HTTP client with response header timeout to prevent hanging on silent servers
22+
transport := http.DefaultTransport.(*http.Transport).Clone()
23+
transport.ResponseHeaderTimeout = 15 * time.Second
24+
client := &http.Client{
25+
Transport: transport,
26+
}
27+
2128
for attempt := 0; attempt < maxRetries; attempt++ {
2229
if attempt > 0 {
2330
o.Logger.Infof("Waiting for %s before retrying data fetch (attempt %d of %d)", retryDelay, attempt+1, maxRetries)
@@ -35,7 +42,7 @@ func (o *Operator) getBatchFromDataService(ctx context.Context, batchURL string,
3542
return nil, err
3643
}
3744

38-
resp, err = http.DefaultClient.Do(req)
45+
resp, err = client.Do(req)
3946
if err == nil && resp.StatusCode == http.StatusOK {
4047
break // Successful request, exit retry loop
4148
}

0 commit comments

Comments
 (0)