-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix: deadline and timeout with retry #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1047,6 +1047,56 @@ func TestRetryTransport_ContextCancellation(t *testing.T) { | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func TestRetryTransport_NoRetryOnContextDeadlineExceeded(t *testing.T) { | ||||||||||||||
| var attempts int32 = 0 | ||||||||||||||
|
|
||||||||||||||
| mockRT := &mockRoundTripper{ | ||||||||||||||
| roundTripFunc: func(req *http.Request) (*http.Response, error) { | ||||||||||||||
| atomic.AddInt32(&attempts, 1) | ||||||||||||||
| // Simulate the error that http.Client produces when Client.Timeout fires | ||||||||||||||
| return nil, fmt.Errorf("Post \"http://localhost:11434/api/generate\": context deadline exceeded (Client.Timeout exceeded while awaiting headers)") | ||||||||||||||
| }, | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| retryRT := &retryTransport{ | ||||||||||||||
| Transport: mockRT, | ||||||||||||||
| MaxRetries: 5, | ||||||||||||||
| RetryStrategy: FixedDelay(1 * time.Millisecond), | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Create a request with an already-expired context to simulate Client.Timeout behavior | ||||||||||||||
| ctx, cancel := context.WithCancel(context.Background()) | ||||||||||||||
| cancel() // Cancel immediately to simulate expired deadline | ||||||||||||||
|
Comment on lines
+1067
to
+1069
|
||||||||||||||
| // Create a request with an already-expired context to simulate Client.Timeout behavior | |
| ctx, cancel := context.WithCancel(context.Background()) | |
| cancel() // Cancel immediately to simulate expired deadline | |
| // Create a request with an already-expired deadline to simulate Client.Timeout behavior | |
| ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(-time.Second)) | |
| defer cancel() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
ctx != nilcheck in the conditionctx := req.Context(); ctx != nil && ctx.Err() != nilis redundant. Per the Go documentation,(*http.Request).Context()always returns a non-nil context — it returnscontext.Background()if no context was set. The same redundant pattern is already present at line 167 (pre-existing code), so this is consistent, but the new code introduces the same unnecessary nil check. Simplifying to justctx.Err() != nilwould be clearer.