Preserve operation timeout identity during HTTP generation

This commit is contained in:
2026-11-19 13:44:42 +00:00
parent 382ccfb14b
commit bcdd6fe06c
2 changed files with 71 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package usecase
import (
"context"
"errors"
"fmt"
"time"
)
@@ -17,7 +18,9 @@ type OperationScope struct {
func NewOperationScope(parent context.Context, duration time.Duration) *OperationScope {
scope := &OperationScope{Context: parent, cancel: func() {}}
if duration > 0 {
scope.cause = errors.New("operation deadline")
// Transports may return context.Cause rather than ctx.Err(). Retain
// deadline identity while keeping this cause unique to the invocation.
scope.cause = fmt.Errorf("operation deadline: %w", context.DeadlineExceeded)
scope.Context, scope.cancel = context.WithTimeoutCause(parent, duration, scope.cause)
}
return scope