Refact/runtime submit#438
Merged
fredbi merged 4 commits intogo-openapi:masterfrom May 9, 2026
Merged
Conversation
This new client method allows for a better control of the request context. refactor(client): split SubmitContext into focused helpers No change in behavior. Debug-dump errors still abort the submit. The contextcheck warning on createHTTPRequest is suppressed inline. Follow-up: threading parentCtx through createHTTPRequest → BuildHTTP → assembleRequest is the next refactor. Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
This commit affects the internal package: client/internal/request. Add BuildHTTPContext as the context-aware variant of BuildHTTP. It derives the request context from the parent and the per-request timeout right after WriteToRequest sets the final timeout value, so the returned http.Request already carries the correct deadline. Cancel is returned to the caller for deferred cleanup. SubmitContext now obtains the request via createHTTPRequestContext and defers a single cancel. Follow-up: Multipart goroutine and producer ctx-awareness. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Problem: when consuming streams to upload, a separate go routine is spawned. It continues draining the file(s) even though the caller has cancelled the request. streamMultipartParts now checks ctx.Err() at iteration boundaries and wraps each file in a ctxReader so io.Copy observes cancellation between Reads. On cancel, the pipe writer is closed with ctx.Err() so the body consumer surfaces context.Canceled (or DeadlineExceeded) as the read error instead of an opaque io.ErrClosedPipe. This is the proactive layer on top of the existing pipe-closure mechanism: when a transport notices ctx cancellation it closes req.Body, which makes pw.Write fail and unwinds the goroutine. The new wiring lets the goroutine bail before the transport reacts — especially useful when a caller cancels mid-upload (large file, slow source) and when req.Body is consumed directly without a transport. Drive-by: io.Copy errors now `return` instead of falling through to the next file's CreatePart, which would have failed on the now-closed pipe. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Drop the legacy no-context BuildHTTP entry point and consolidate around BuildHTTPContext. Public-facing change: Runtime.CreateHttpRequest is deprecated in favor of the new Runtime.CreateHTTPRequestContext. Callers that set a per-request timeout via ClientRequestWriter must migrate, otherwise the cancel func is dropped and the timer leaks; previously such timeouts were silently ignored on this path (only Submit honored them), so the behavior change is explicit and documented inline. Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (79.66%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #438 +/- ##
==========================================
+ Coverage 84.76% 84.79% +0.03%
==========================================
Files 58 58
Lines 3767 3809 +42
==========================================
+ Hits 3193 3230 +37
- Misses 434 440 +6
+ Partials 140 139 -1 ☔ View full report in Codecov by Sentry. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change type
Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update
Short description
Fixes
Full description
Checklist