cluster: bound connection acquisition inside the lock attempt

A blocking dial ran under context.Background(), so a caller supplying
grpc.WithBlock() could wait past the attempt window before the RPC
deadline even started. The attempt context now covers both
getOrCreateConnection and the DistributedLock call, and WithGrpcClient
threads it into GrpcDial on both the cached and streaming paths.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
user.emailandDevin committed 2026-10-26 18:42:49 -07:00
1 parent dbf2c3d30f
commit db02eea349
2 files changed
+16 -15

No files matched your search

+7 -6
View File
@@ -435,11 +435,12 @@ func (lock *LiveLock) doLock(lockDuration, attemptTimeout time.Duration) (errorM
previousHostFiler := lock.hostFiler
previousOwner := lock.owner
err = pb.WithFilerClient(false, 0, lock.hostFiler, lock.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
// Bound the attempt so an unreachable owner fails within the retry
// window.
ctx, cancel := context.WithTimeout(context.Background(), attemptTimeout)
defer cancel()
// Bound the whole attempt — connection acquisition included — so an
// unreachable owner fails within the retry window.
ctx, cancel := context.WithTimeout(context.Background(), attemptTimeout)
defer cancel()
err = pb.WithGrpcClient(ctx, false, 0, func(grpcConnection *grpc.ClientConn) error {
client := filer_pb.NewSeaweedFilerClient(grpcConnection)
resp, err := client.DistributedLock(ctx, &filer_pb.LockRequest{
Name: lock.key,
SecondsToLock: int64(lockDuration.Seconds()),
@@ -484,7 +485,7 @@ func (lock *LiveLock) doLock(lockDuration, attemptTimeout time.Duration) (errorM
}
}
return err
})
}, lock.hostFiler.ToGrpcAddress(), false, lock.grpcDialOption)
if err != nil && !lock.hostFiler.Equals(lock.lc.seedFiler) {
lock.consecutiveFailures++