fix: cap the blockmaster link's reconnect back-off at 2 s

A volume process will wait through a master outage on one channel, so
gRPC's default back-off (to 120 s) would delay the first call after the
master returns by up to two minutes. Only the two blockmaster dials
change; MinConnectTimeout stays 5 s for the handshake.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-23 20:45:57 -08:00
1 parent 48b4a36bfe
commit 630451644f
4 files changed
+23 -4

No files matched your search

@@ -26,7 +26,7 @@ func newChunkMaintenance(cat *chunkstore.Catalog, blobs chunkstore.BlobDeleter,
if defaultChunkGCGrace <= max(defaultChunkCutTimeout, chunkstore.DefaultOpDeadline)+defaultChunkMaintenanceTimeout {
return nil, closeFn, errors.New("automatic GC grace does not cover cut/copy and mark bounds")
}
conn, err := link.Dial(master)
conn, err := link.Dial(master, link.MasterReconnect())
if err != nil {
return nil, closeFn, err
}
+1 -1
View File
@@ -267,7 +267,7 @@ func New(cfg Config) (*Host, error) {
lg = log.Default()
}
conn, err := link.Dial(cfg.MasterAddr)
conn, err := link.Dial(cfg.MasterAddr, link.MasterReconnect())
if err != nil {
return nil, fmt.Errorf("volume.New: dial master %q: %w", cfg.MasterAddr, err)
}
@@ -69,8 +69,9 @@ func TestMasterLinkReconnectsWithinTwoSeconds(t *testing.T) {
case <-sink.got:
lag := time.Since(back)
t.Logf("first heartbeat %v after the master returned", lag.Round(10*time.Millisecond))
if lag > 2400*time.Millisecond {
t.Fatalf("master link reconnected %v after the master returned; want <= 2.4 s", lag.Round(10*time.Millisecond))
// 2 s cap + 20 % jitter, plus one 200 ms heartbeat tick once connected.
if lag > 2600*time.Millisecond {
t.Fatalf("master link reconnected %v after the master returned; want <= 2.6 s", lag.Round(10*time.Millisecond))
}
case <-time.After(60 * time.Second):
t.Fatal("no heartbeat within 60 s of the master's return")
+18
View File
@@ -6,7 +6,10 @@
package link
import (
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/credentials/insecure"
)
@@ -45,3 +48,18 @@ func NewServer(cfg ServerConfig, opts ...grpc.ServerOption) *grpc.Server {
all = append(all, opts...)
return grpc.NewServer(all...)
}
// MasterReconnect caps the reconnect back-off of a long-lived link to
// blockmaster. A volume process waits for an unreachable master instead of
// exiting, so one channel can live through a long outage; with gRPC's default
// back-off (base 1 s, x1.6, jitter 0.2, max 120 s: grpc@v1.80.0
// backoff/backoff.go:48-51) the first call after the master returns could lag
// by up to two minutes. Capped at 2 s, the lag stays about 2 s. The connect
// timeout must be set: WithConnectParams otherwise makes it equal to the
// back-off step (dialoptions.go:313-314), too short for a TLS handshake.
func MasterReconnect() grpc.DialOption {
return grpc.WithConnectParams(grpc.ConnectParams{
Backoff: backoff.Config{BaseDelay: time.Second, Multiplier: 1.6, Jitter: 0.2, MaxDelay: 2 * time.Second},
MinConnectTimeout: 5 * time.Second,
})
}