Repository navigation
Conversation
dd2dffb to
2e725db
Compare
tonistiigi
left a comment
There was a problem hiding this comment.
Agentic:
I found four issues while testing this change. Each one is reproduced below.
1. Deadline causes are still lost intermittently (util/grpcerrors/intercept.go#L44)
go test -count=30 ./session/auth fails 7 of 30 runs on this branch. Every failure is the bare DeadlineExceeded: context deadline exceeded.
I added logging inside the interceptor. Each failing call received a bare DeadlineExceeded status with no details, 0.3–0.6 ms after the context deadline had passed. At that point ctx.Err() and context.Cause(ctx) were both still nil, so the restore branch was skipped. The server gets the same deadline through grpc-timeout, so its bare status can arrive before the client context's timer has run.
This is the code path from #7444, so the fix does not hold reliably. Cancellation is not affected, because cancel() sets Err() immediately.
2. The RPC code is not kept for some causes (util/grpcerrors/intercept.go#L48)
Code() checks errdefs.IsInternal before it looks at the Code() method of withCodeError (util/grpcerrors/grpcerrors.go#L118). As a result, WrapCode cannot override that classification. With the invoker returning a bare codes.Canceled:
| cancel cause | grpcerrors.Code and ToGRPC code |
|---|---|
errors.New("custom") |
Canceled |
errdefs.Internal(...) |
Internal |
errors.WithStack(syscall.ENOSPC) |
ResourceExhausted |
This contradicts "Preserve the RPC status code" in the commit message. For example, if a sibling in an errgroup.WithContext group fails with ENOSPC, an RPC that was only canceled is reported as ResourceExhausted.
3. The restored error no longer carries a gRPC status (util/grpcerrors/intercept.go#L48)
Before this change, the interceptor returned *grpcStatusError, which implements GRPCStatus(). The new error does not, so status.Code(err) and status.FromError(err) now return Unknown for these errors. This includes contexts with no custom cause (plain context.WithCancel).
If the cause is itself a status error, the two code helpers disagree. With a cause of status.Error(codes.Unavailable, ...), status.Code returns Unavailable, while grpcerrors.Code and ToGRPC return Canceled.
The client package is public API, so callers that check Solve errors with status.Code will see this change.
4. The parent-cancel half of TestSessionAuthTimeout never reaches the RPC (session/auth/auth_test.go#L79-L84)
The test cancels the parent context before making the call. Manager.Get checks ctx.Done() first (session/manager.go#L171-L174). So the call returns no active session for <id>: build canceled: context canceled without ever making an RPC. These assertions pass with or without the interceptor change.
Fixes, for reference:
- 1: when the status is
DeadlineExceededandctx.Deadline()has already passed, wait onctx.Done()before reading the cause. A context whoseDeadline()is in the past and whoseDone()closes later tests this deterministically. - 2 and 3: one dedicated error type fixes both. It returns the cause from
Error()/Unwrap()and the original status fromGRPCStatus()/Code(), andCode()checks it beforeIsInternal. - 4: cancel while the handler is blocked, as
TestUnaryClientCancellationCausedoes withstarted.
2e725db to
03aa327
Compare
Restore the local context cause when a unary RPC returns a matching bare cancellation or deadline status. Handle this in the shared client interceptor so session-derived causes and auth timeout messages survive. Wait for local cancellation when a bare deadline response arrives after the deadline but before the client context timer fires. Keep the RPC code and GRPCStatus independent of the cause's own error classification, while leaving distinct remote errors intact. Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
03aa327 to
e898eb9
Compare
fixes #7444
Preserve the local context cause when a unary RPC returns a matching bare cancellation or deadline error. This makes session-auth timeouts identify the operation that timed out and also preserves causes attached to session-derived contexts. When a deadline response arrives after the deadline but before the local context timer fires, wait for cancellation before reading the cause.
Keep the RPC status code consistent across
grpcerrors.Code,status.Code, and serialization, even when the cause carries a different status or is classified as an internal error. Distinct remote errors and configured timeouts remain unchanged.