s3: blame no filer for a deadline gRPC reports before ctx.Err() (#13098)

The filer walk told the caller's expiry apart from a filer failure by
ctx.Err() alone. A server-side DeadlineExceeded can reach the client
before the context's own timer runs, so the walk recorded a failure
against each filer and moved on with no budget left, the same race
LookupVolumeIds already guards against.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 authored and GitHub committed 2026-11-28 15:31:57 -08:00
1 parent 5b7e2d9e9e
commit e7cbfdcc44
2 files changed
+49 -1

No files matched your search

+16 -1
View File
@@ -13,7 +13,9 @@ import (
"github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
"github.com/seaweedfs/seaweedfs/weed/security"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/status"
"github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
@@ -139,7 +141,7 @@ func (s3a *S3ApiServer) withFilerClientFailover(ctx context.Context, preferred p
// the next one has no time left to answer either. Recorded as a failure, a
// slow master upstream would flag every filer in the walk, and the three
// that open the circuit take unrelated object reads down with them.
if ctx.Err() != nil {
if callerContextEnded(ctx, err) {
glog.V(2).Infof("WithFilerClient: giving up on %s, the caller's context ended: %v", filer, err)
return err
}
@@ -175,6 +177,19 @@ func (s3a *S3ApiServer) withFilerClientFailover(ctx context.Context, preferred p
// the request was provably never sent and the walk may continue.
var errFilerConnNotReady = errors.New("filer connection not ready")
// callerContextEnded reports whether ctx, not the filer, ended the call. gRPC
// can surface its own DeadlineExceeded a tick before ctx.Err() becomes visible.
func callerContextEnded(ctx context.Context, err error) bool {
if ctx.Err() != nil {
return true
}
if !errors.Is(err, context.DeadlineExceeded) && status.Code(err) != codes.DeadlineExceeded {
return false
}
deadline, ok := ctx.Deadline()
return ok && !deadline.After(time.Now())
}
// filerConnReadyWait bounds how long a candidate gets to bring its channel up
// before the walk tries the next filer.
const filerConnReadyWait = 2 * time.Second
@@ -188,6 +188,39 @@ func TestFailoverDoesNotBlameFilersForTheCallersExpiredBudget(t *testing.T) {
}
}
// pastDeadlineCtx is the window after gRPC has reported the deadline but before
// the context's own timer has run: the deadline is behind it, Err is still nil.
type pastDeadlineCtx struct{ context.Context }
func (pastDeadlineCtx) Deadline() (time.Time, bool) { return time.Now().Add(-time.Millisecond), true }
func TestFailoverDoesNotBlameFilersForADeadlineReportedBeforeCtxErr(t *testing.T) {
firstAddr := startFakeFiler(t, &hangingCollectionFiler{})
secondAddr := startFakeFiler(t, &hangingCollectionFiler{})
s3a := newFailoverTestServer(t, firstAddr, secondAddr)
ctx := pastDeadlineCtx{context.Background()}
var fnCalls int
for attempt := 0; attempt < 5; attempt++ {
err := s3a.withFilerClient(ctx, false, func(filer_pb.SeaweedFilerClient) error {
fnCalls++
return status.Error(codes.DeadlineExceeded, "context deadline exceeded")
})
if status.Code(err) != codes.DeadlineExceeded {
t.Fatalf("attempt %d: want the caller's deadline surfaced, got %v", attempt, err)
}
}
for _, addr := range []pb.ServerAddress{firstAddr, secondAddr} {
if s3a.filerClient.ShouldSkipUnhealthyFiler(addr) {
t.Errorf("filer %s was flagged unhealthy for the caller's own deadline", addr)
}
}
if fnCalls != 5 {
t.Errorf("fn ran %d times over 5 attempts; the walk went on to another filer with no budget left", fnCalls)
}
}
// hangingAssignFiler answers AssignVolume only when the caller gives up,
// standing in for a filer still waiting on the master for a volume.
type hangingAssignFiler struct {