diff options
| author | Rob Pike <r@golang.org> | 2015-05-04 13:09:31 -0700 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2015-05-05 16:02:19 +0000 |
| commit | 64c39a3093db3976201697bb817d5705afc66bed (patch) | |
| tree | 5a4a1c8c92486044104d3a74b9a78792532452a9 /src/text/template/parse/parse.go | |
| parent | 5a828cfcde20c25b9b3a3387159a77eb084383b8 (diff) | |
| download | go-64c39a3093db3976201697bb817d5705afc66bed.tar.xz | |
text/template: shut down lexing goroutine on error
When a parse error occurred, the lexing goroutine would lay idle.
It's not likely a problem but if the program is for some reason
accepting badly formed data repeatedly, it's wasteful.
The solution is easy: Just drain the input on error. We know this
will succeed because the input is always a string and is therefore
guaranteed finite.
With debugging prints in the package tests I've shown this is effective,
shutting down 79 goroutines that would otherwise linger, out of 123 total.
Fixes #10574.
Change-Id: I8aa536e327b219189a7e7f604a116fa562ae1c39
Reviewed-on: https://go-review.googlesource.com/9658
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/text/template/parse/parse.go')
| -rw-r--r-- | src/text/template/parse/parse.go | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/text/template/parse/parse.go b/src/text/template/parse/parse.go index f4daa37954..6eb303801b 100644 --- a/src/text/template/parse/parse.go +++ b/src/text/template/parse/parse.go @@ -196,6 +196,7 @@ func (t *Tree) recover(errp *error) { panic(e) } if t != nil { + t.lex.drain() t.stopParse() } *errp = e.(error) |
