Skip to content
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

html/template: deadlock if "dot" method is used to execute template from same set #43855

Closed
ianlancetaylor opened this issue Jan 22, 2021 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@ianlancetaylor
Copy link
Contributor

The fix for #39807 has introduced a potential deadlock if a method of the "dot" value in an html/template is used to execute another template from the same template set.

This code, written in the form of a test, demonstrates the problem. If the test is run, it hangs or dies with fatal error: all goroutines are asleep - deadlock!.

// recursiveInvoker is for TestRecursiveExecuteViaMethod.
type recursiveInvoker struct{
	t    *testing.T
	tmpl *Template
}

func (r *recursiveInvoker) Recur() (string, error) {
	var sb strings.Builder
	if err := r.tmpl.ExecuteTemplate(&sb, "subroutine", nil); err != nil {
		r.t.Fatal(err)
	}
	return sb.String(), nil
}

func TestRecursiveExecuteViaMethod(t *testing.T) {
	tmpl := New("")
	top, err := tmpl.New("x.html").Parse(`{{.Recur}}`)
	if err != nil {
		t.Fatal(err)
	}
	_, err = tmpl.New("subroutine").Parse(`<a href="/x?p={{"'a<b'"}}">`)
	if err != nil {
		t.Fatal(err)
	}
	r := &recursiveInvoker{
		t:    t,
		tmpl: tmpl,
	}
	if err := top.Execute(io.Discard, r); err != nil {
		t.Fatal(err)
	}
}
@ianlancetaylor ianlancetaylor added NeedsFix The path to resolution is known, but the work has not been done. release-blocker labels Jan 22, 2021
@ianlancetaylor ianlancetaylor added this to the Go1.16 milestone Jan 22, 2021
@ianlancetaylor
Copy link
Contributor Author

I don't see a way to fix this. At least not without introducing some ugly connection between text/template and html/template, which we should not do at this stage of the release.

I think we have to roll back CLs 274450 and 279492, though perhaps we should keep the tests.

@gopherbot
Copy link

Change https://golang.org/cl/285957 mentions this issue: html/template: revert "avoid race when escaping updates template"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants
@ianlancetaylor @gopherbot and others