-
Notifications
You must be signed in to change notification settings - Fork 18k
text/template: should t.init()
be executed before t.muTmpl.Lock()
in AddParseTree()
method?
#48436
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
Comments
Thanks. I don't know how much sense that makes, but it used to work, so I guess we should let it keep working. |
@gopherbot Please open backports to 1.16 and 1.17 Fix regression in |
Backport issue(s) opened: #48443 (for 1.16), #48444 (for 1.17). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases. |
Change https://golang.org/cl/350730 mentions this issue: |
Change https://golang.org/cl/351115 mentions this issue: |
Change https://golang.org/cl/351116 mentions this issue: |
…king it For #39807 For #48436 Fixes #48444 Change-Id: I75f82fd8738dd2f11f0c69b1230e1be1abc36024 Reviewed-on: https://go-review.googlesource.com/c/go/+/350730 Trust: Ian Lance Taylor <iant@golang.org> Trust: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> (cherry picked from commit ba1c52d) Reviewed-on: https://go-review.googlesource.com/c/go/+/351115
…king it For #39807 For #48436 Fixes #48443 Change-Id: I75f82fd8738dd2f11f0c69b1230e1be1abc36024 Reviewed-on: https://go-review.googlesource.com/c/go/+/350730 Trust: Ian Lance Taylor <iant@golang.org> Trust: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> (cherry picked from commit ba1c52d) Reviewed-on: https://go-review.googlesource.com/c/go/+/351116
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes for go1.17.1 and 1.16.8, but not in 1.16.7
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I read the CL "add lock for Template.tmpl to fix data race" https://golang.org/cl/348580. I'm a little confused about the following function fix:
As you can see, it executes
t.muTmpl.Lock()
beforet.init()
.The
init()
method and thecommon
structure are listed below.In the
init()
method, ift.common
isnil
, thet.common
will be initialized, including the default initialization ofmuTmpl
.Now return to the
AddParseTree()
method.Because it executes
t.init()
, which means thatt.common
may benil
, executingt.muTmpl.Lock()
first may producenil panic
. So in this method, shouldt.init()
be executed beforet.muTmpl.Lock()
?A simple reproduction procedure:
What did you expect to see?
normal exit
What did you see instead?
The text was updated successfully, but these errors were encountered: