Skip to content

resources: Fix context canceled on GetRemote with per-request timeout - #14612

Merged
bep merged 1 commit into
gohugoio:masterfrom
bep:fix/issue-14611
Mar 10, 2026
Merged

bep merged 1 commit into
gohugoio:masterfrom
bep:fix/issue-14611

Conversation

@bep

@bep bep commented Mar 10, 2026 •

Copy link
Copy Markdown
Member

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

@bep
bep force-pushed the fix/issue-14611 branch from 35aa3ad to ea4dbfc Compare March 10, 2026 09:26
@bep
bep marked this pull request as ready for review March 10, 2026 09:34
@gemini-code-assist

Copy link
Copy Markdown
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 the getRes closure to the outer FromRemote scope, 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.

Comment thread resources/resource_factories/create/remote.go Outdated
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bep
bep merged commit 842d8f1 into gohugoio:master Mar 10, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

resources.GetRemote: context canceled when fetching many remote images from the same host

2 participants