Repository navigation
resources: Fix context canceled on GetRemote with per-request timeout - #14612
Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #14611 where resources.GetRemote with a per-request timeout option would fail with "context canceled" errors. The root cause was that defer cancel() for the timeout context was inside the getRes closure, causing the context to be canceled before io.ReadAll(res.Body) in the outer scope could read the response body. The fix moves the cancel function management to the outer scope.
Changes:
- Moved the timeout context cancel function (
cancelTimeout) from thegetResclosure to the outerFromRemotescope, ensuring the context remains active while the response body is being read. - Added explicit cancel calls in both the error path and via defer after successful response handling.
- Added an integration test that verifies body reading works correctly when the server sends headers immediately but delays the body.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| resources/resource_factories/create/remote.go | Moves cancelTimeout out of getRes closure so context stays valid during body read |
| resources/resource_factories/create/create_integration_test.go | Adds test for issue #14611: server sends headers immediately but delays body, with per-request timeout |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
The per-request timeout context was cancelled via defer in the getRes closure, before io.ReadAll(res.Body) in the outer scope could read the response body. Fix this by returning the cancel function from getRes so each caller manages its own cancel lifecycle. Fixes gohugoio#14611 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
The per-request timeout context was cancelled via defer in the getRes
closure, before io.ReadAll(res.Body) in the outer scope could read
the response body. Move cancel to the outer scope so it runs after
the body is fully read.
Fixes #14611