Skip to content

Commit 7b976d1

Browse files
committed
Revert fix and add a new one
1 parent a75d128 commit 7b976d1

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

operator/pkg/operator.go

Lines changed: 6 additions & 3 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,7 +65,9 @@ type Operator struct {
6465
}
6566

6667
const (
67-
BatchDownloadTimeout = 1 * time.Minute
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 = 5 * time.Minute
6871
BatchDownloadMaxRetries = 3
6972
BatchDownloadRetryDelay = 5 * time.Second
7073
UnverifiedBatchOffset = 100

operator/pkg/s3.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,22 @@ 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 = 60 * 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)
24-
time.Sleep(retryDelay)
31+
select {
32+
case <-time.After(retryDelay):
33+
// Wait before retrying
34+
case <-ctx.Done():
35+
return nil, ctx.Err()
36+
}
2537
retryDelay *= 2 // Exponential backoff. Ex: 5s, 10s, 20s
2638
}
2739

@@ -30,7 +42,7 @@ func (o *Operator) getBatchFromDataService(ctx context.Context, batchURL string,
3042
return nil, err
3143
}
3244

33-
resp, err = http.DefaultClient.Do(req)
45+
resp, err = client.Do(req)
3446
if err == nil && resp.StatusCode == http.StatusOK {
3547
break // Successful request, exit retry loop
3648
}

0 commit comments

Comments
 (0)