@@ -85,10 +85,11 @@ func (me *service) Create(ctx context.Context, v *role_arn.Settings) (*api.Stub,
8585 connValue .AWSWebIdentity .RoleARN = v .RoleARN
8686 }
8787
88- ctxRetry , cancel , retryTimeout , err := computeRetryContext (ctx , timeoutDeadlineBuffer , role_arn .DefaultCreateTimeout )
88+ retryTimeout , err := computeRetryTimeout (ctx , timeoutDeadlineBuffer , role_arn .DefaultCreateTimeout )
8989 if err != nil {
9090 return nil , err
9191 }
92+ ctxRetry , cancel := context .WithTimeout (ctx , retryTimeout )
9293 defer cancel ()
9394
9495 if err = retry .RetryContext (ctxRetry , retryTimeout , func () * retry.RetryError {
@@ -100,29 +101,20 @@ func (me *service) Create(ctx context.Context, v *role_arn.Settings) (*api.Stub,
100101 return & api.Stub {ID : v .AWSConnectionID , Name : v .AWSConnectionID }, nil
101102}
102103
103- // computeRetryContext computes a safe retry timeout based on the incoming ctx deadline.
104+ // computeRetryTimeout computes a safe retry timeout based on the incoming ctx deadline.
104105// - timeoutDeadlineBuffer: amount of time to reserve for finalization (e.g. 1 minute).
105106// - defaultTimeout: fallback when caller didn't provide a deadline.
106- // Returns the derived ctx (with timeout), its cancel func, the retryTimeout, or an error
107- // if the caller's deadline already expired.
108- func computeRetryContext (ctx context.Context , timeoutDeadlineBuffer time.Duration , defaultTimeout time.Duration ) (context.Context , context.CancelFunc , time.Duration , error ) {
107+ // Returns the derived timeout, or an error if the caller's deadline already expired (taking the buffer into account as well).
108+ func computeRetryTimeout (ctx context.Context , timeoutDeadlineBuffer time.Duration , defaultTimeout time.Duration ) (time.Duration , error ) {
109109 if dl , ok := ctx .Deadline (); ok {
110- remaining := time .Until (dl )
110+ remaining := time .Until (dl ) - timeoutDeadlineBuffer
111111 if remaining <= 0 {
112- return nil , nil , 0 , context .DeadlineExceeded
112+ return 0 , context .DeadlineExceeded
113113 }
114- var retryTimeout time.Duration
115- if remaining > timeoutDeadlineBuffer {
116- retryTimeout = remaining - timeoutDeadlineBuffer
117- } else {
118- retryTimeout = remaining
119- }
120- ctxRetry , cancel := context .WithTimeout (ctx , retryTimeout )
121- return ctxRetry , cancel , retryTimeout , nil
114+ return remaining , nil
122115 }
123116 // no deadline: use conservative default
124- ctxRetry , cancel := context .WithTimeout (ctx , defaultTimeout )
125- return ctxRetry , cancel , defaultTimeout , nil
117+ return defaultTimeout , nil
126118}
127119
128120// classifyRetryError encapsulates which errors should be retried.
0 commit comments