Skip to content

Commit 93b76ee

Browse files
authored
Fix issue with context timeout below 1 second (#295)
1 parent 3780d5b commit 93b76ee

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

azblob/zc_policy_retry.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,25 +181,25 @@ func NewRetryPolicyFactory(o RetryOptions) pipeline.Factory {
181181
}
182182

183183
// Set the server-side timeout query parameter "timeout=[seconds]"
184-
timeout := int32(o.TryTimeout.Seconds()) // Max seconds per try
185-
if deadline, ok := ctx.Deadline(); ok { // If user's ctx has a deadline, make the timeout the smaller of the two
186-
t := int32(deadline.Sub(time.Now()).Seconds()) // Duration from now until user's ctx reaches its deadline
187-
logf("MaxTryTimeout=%d secs, TimeTilDeadline=%d sec\n", timeout, t)
184+
timeout := o.TryTimeout // Max time per try
185+
if deadline, ok := ctx.Deadline(); ok { // If user's ctx has a deadline, make the timeout the smaller of the two
186+
t := deadline.Sub(time.Now()) // Duration from now until user's ctx reaches its deadline
187+
logf("MaxTryTimeout=%d secs, TimeTilDeadline=%d sec\n", int32(timeout.Seconds()), int32(t.Seconds()))
188188
if t < timeout {
189189
timeout = t
190190
}
191191
if timeout < 0 {
192192
timeout = 0 // If timeout ever goes negative, set it to zero; this happen while debugging
193193
}
194-
logf("TryTimeout adjusted to=%d sec\n", timeout)
194+
logf("TryTimeout adjusted to=%d sec\n", int32(timeout.Seconds()))
195195
}
196196
q := requestCopy.Request.URL.Query()
197-
q.Set("timeout", strconv.Itoa(int(timeout+1))) // Add 1 to "round up"
197+
q.Set("timeout", strconv.Itoa(int(timeout.Seconds()+1))) // Add 1 to "round up"
198198
requestCopy.Request.URL.RawQuery = q.Encode()
199199
logf("Url=%s\n", requestCopy.Request.URL.String())
200200

201201
// Set the time for this particular retry operation and then Do the operation.
202-
tryCtx, tryCancel := context.WithTimeout(ctx, time.Second*time.Duration(timeout))
202+
tryCtx, tryCancel := context.WithTimeout(ctx, timeout)
203203
//requestCopy.Body = &deadlineExceededReadCloser{r: requestCopy.Request.Body}
204204
response, err = next.Do(tryCtx, requestCopy) // Make the request
205205
/*err = improveDeadlineExceeded(err)

0 commit comments

Comments
 (0)