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

text/template: leaks goroutines on errors #10614

Closed
dvyukov opened this issue Apr 29, 2015 · 5 comments
Closed

text/template: leaks goroutines on errors #10614

dvyukov opened this issue Apr 29, 2015 · 5 comments
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Apr 29, 2015

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

@dvyukov dvyukov added this to the Go1.5 milestone Apr 29, 2015
@rambocoder
Copy link

@dvyukov how did you know to panic and look at the stack trace for a goroutine stuck on the send channel? go-fuzz seems to be about testing if the error happens inside of the API call by looking for a panic or a wrong error output, this is a very interesting twist to also see if a goroutine is leaked.

@dvyukov
Copy link
Member Author

dvyukov commented Apr 29, 2015

@rambocoder I noticed it accidentally. Since I reuse the same process for thousands of tests, lots of crash reports contained thousands of lexer goroutines in the dump.
I am not sure how reliably detect goroutine leaks, since APIs are generally allowed to create some amount of background goroutines. I guess it is possible to use some heuristic. But I would wait for at least a second such case first.

@dvyukov
Copy link
Member Author

dvyukov commented Apr 29, 2015

@rambocoder But of course in your own Fuzz function you are free to call runtime.NumGoroutine and panic if the number increases.

@gravis
Copy link

gravis commented Apr 29, 2015

Duplicates #10574

@mdempsky
Copy link
Member

Closing as duplicate.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
@rsc rsc unassigned robpike Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants