Skip to content

text/template: leaks goroutines on errors #10614

@dvyukov

Description

@dvyukov

The following program leaves a hanged goroutine. If a server reloads templates on the fly, this behavior can leads to unbounded number of leaked goroutines.

package main

import (
    "html/template"
    "time"
)

func main() {
    template.New("foo").Parse("{{.")
    time.Sleep(time.Second)
    panic("who's there?")
}
panic: who's there?

goroutine 1 [running]:
main.main()
    /tmp/htmltempl.go:11 +0x297

goroutine 5 [chan send]:
text/template/parse.(*lexer).errorf(0xc2080c2000, 0x5d8290, 0xf, 0x0, 0x0, 0x0, 0xffffff01)
    src/text/template/parse/lex.go:165 +0xca
text/template/parse.lexInsideAction(0xc2080c2000, 0x623b78)
    src/text/template/parse/lex.go:280 +0xaf7
text/template/parse.(*lexer).run(0xc2080c2000)
    src/text/template/parse/lex.go:198 +0x5d
created by text/template/parse.lex
    src/text/template/parse/lex.go:191 +0x1b9

on commit ccc76db

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions