Skip to content

Conversation

@bep
Copy link
Member

@bep bep commented Apr 20, 2025

Fixes #13627

@bep bep force-pushed the feat/loop-13627 branch 2 times, most recently from c644f3e to 7074c27 Compare April 20, 2025 17:56
@bep bep requested a review from Copilot April 20, 2025 18:41
Copy link

Copilot AI left a comment

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 addresses issue #13627 by detecting and failing on infinite template recursion. Key changes include:

  • Adding a new integration test (TestTemplateLoop) to verify infinite recursion detection.
  • Introducing a recursion level check in TemplateStore with a threshold of 500.
  • Removing the previously used timeout mechanism for partial inclusion in favor of direct infinite recursion detection.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tpl/tplimpl/templatestore_integration_test.go Added a test to check for infinite recursion detection.
tpl/tplimpl/templatestore.go Introduced level tracking and recursion check with a threshold.
tpl/template.go Updated template info to include recursion level.
tpl/partials/partials_integration_test.go Updated expected error message for infinite recursion detection.
tpl/partials/partials.go Replaced the timeout-based partial inclusion with a direct call, and updated associated error assignment.
Comments suppressed due to low confidence (1)

tpl/partials/partials.go:202

  • The field 'mangager' appears to be a typo; consider renaming it to 'manager' to improve clarity.
r.mangager = depsManagerShared
Comment on lines 111 to 114
func (ns *Namespace) Include(ctx context.Context, name string, contextList ...any) (any, error) {
res := ns.includWithTimeout(ctx, name, contextList...)
res := ns.include(ctx, name, contextList...)
if res.err != nil {
return nil, res.err
Copy link

Copilot AI Apr 20, 2025

Choose a reason for hiding this comment

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

Replacing the call to ns.includWithTimeout with ns.include removes the timeout safeguard, which may lead to hanging execution if a partial is slow but not recursively calling itself. Consider reintroducing a timeout mechanism or an alternative safeguard for non-recursive slow partials.

Copilot uses AI. Check for mistakes.
@bep bep force-pushed the feat/loop-13627 branch 4 times, most recently from 30acb51 to a4eae43 Compare April 21, 2025 09:21
@bep bep changed the title tpl: Detect and fail on infinite template recursion Apr 21, 2025
@bep bep force-pushed the feat/loop-13627 branch 2 times, most recently from 66e9729 to e26adcf Compare April 21, 2025 11:03
@bep bep force-pushed the feat/loop-13627 branch from e26adcf to 7f799eb Compare April 21, 2025 12:23
@bep bep merged commit 4eb0e42 into gohugoio:master Apr 21, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant