gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.39k stars 7.49k forks source link

Data race in template test #5926

Closed bep closed 8 months ago

bep commented 5 years ago

Probably a bug in Go.


WARNING: DATA RACE
Read at 0x00c004fdf7d0 by goroutine 143:
  runtime.mapaccess1_faststr()
      /home/travis/.gimme/versions/go1.12.2.linux.amd64/src/runtime/map_faststr.go:12 +0x0
  text/template.(*state).walkTemplate()
      /home/travis/.gimme/versions/go1.12.2.linux.amd64/src/text/template/exec.go:398 +0x136
  text/template.(*state).walk()
      /home/travis/.gimme/versions/go1.12.2.linux.amd64/src/text/template/exec.go:267 +0x2a5
  text/template.(*state).walk()
      /home/travis/.gimme/versions/go1.12.2.linux.amd64/src/text/template/exec.go:262 +0x1a0
  text/template.(*Template).execute()
      /home/travis/.gimme/versions/go1.12.2.linux.amd64/src/text/template/exec.go:217 +0x2f8
  html/template.(*Template).Execute()
      /home/travis/.gimme/versions/go1.12.2.linux.amd64/src/text/template/exec.go:200 +0xd3
  github.com/gohugoio/hugo/tpl.(*TemplateAdapter).Execute()
      /home/travis/src/hugo/tpl/template.go:163 +0xf8
  github.com/gohugoio/hugo/hugolib.(*Site).renderForLayouts()
      /home/travis/src/hugo/hugolib/site.go:1801 +0xc8
  github.com/gohugoio/hugo/hugolib.(*Site).renderAndWritePage()
      /home/travis/src/hugo/hugolib/site.go:1717 +0x297
  github.com/gohugoio/hugo/hugolib.pageRenderer()
      /home/travis/src/hugo/hugolib/site_render.go:152 +0x8ed
Previous write at 0x00c004fdf7d0 by goroutine 121:
  runtime.mapassign_faststr()
      /home/travis/.gimme/versions/go1.12.2.linux.amd64/src/runtime/map_faststr.go:202 +0x0
  text/template.(*Template).associate()
      /home/travis/.gimme/versions/go1.12.2.linux.amd64/src/text/template/template.go:222 +0x19e
  text/template.(*Template).AddParseTree()
      /home/travis/.gimme/versions/go1.12.2.linux.amd64/src/text/template/template.go:128 +0x2ab
  html/template.(*escaper).commit()
      /home/travis/.gimme/versions/go1.12.2.linux.amd64/src/html/template/escape.go:810 +0x2b6
  html/template.escapeTemplate()
      /home/travis/.gimme/versions/go1.12.2.linux.amd64/src/html/template/escape.go:38 +0x318
  html/template.(*Template).escape()
      /home/travis/.gimme/versions/go1.12.2.linux.amd64/src/html/template/template.go:102 +0x319
  html/template.(*Template).Execute()
      /home/travis/.gimme/versions/go1.12.2.linux.amd64/src/html/template/template.go:119 +0x3c
  github.com/gohugoio/hugo/tpl.(*TemplateAdapter).Execute()
      /home/travis/src/hugo/tpl/template.go:163 +0xf8
  github.com/gohugoio/hugo/hugolib.(*Site).renderForLayouts()
      /home/travis/src/hugo/hugolib/site.go:1801 +0xc8
  github.com/gohugoio/hugo/hugolib.(*Site).renderAndWritePage()
      /home/travis/src/hugo/hugolib/site.go:1717 +0x297
  github.com/gohugoio/hugo/hugolib.pageRenderer()
      /home/travis/src/hugo/hugolib/site_render.go:152 +0x8ed
Goroutine 143 (running) created at:
  github.com/gohugoio/hugo/hugolib.(*Site).renderPages()
      /home/travis/src/hugo/hugolib/site_render.go:73 +0x199
  github.com/gohugoio/hugo/hugolib.(*Site).render()
      /home/travis/src/hugo/hugolib/site.go:1161 +0x8b
  github.com/gohugoio/hugo/hugolib.(*HugoSites).render()
      /home/travis/src/hugo/hugolib/hugo_sites_build.go:302 +0x9f0
  github.com/gohugoio/hugo/hugolib.(*HugoSites).Build.func4()
      /home/travis/src/hugo/hugolib/hugo_sites_build.go:121 +0x57
  runtime/trace.WithRegion()
      /home/travis/.gimme/versions/go1.12.2.linux.amd64/src/runtime/trace/annotation.go:137 +0x10b
  github.com/gohugoio/hugo/hugolib.(*HugoSites).Build()
      /home/travis/src/hugo/hugolib/hugo_sites_build.go:123 +0xa50
  github.com/gohugoio/hugo/hugolib.(*sitesBuilder).build()
      /home/travis/src/hugo/hugolib/testhelpers_test.go:440 +0x1a7
  github.com/gohugoio/hugo/hugolib.TestEmbeddedTemplates()
      /home/travis/src/hugo/hugolib/testhelpers_test.go:407 +0x2c8
  testing.tRunner()
      /home/travis/.gimme/versions/go1.12.2.linux.amd64/src/testing/testing.go:865 +0x163
Goroutine 121 (finished) created at:
  github.com/gohugoio/hugo/hugolib.(*Site).renderPages()
      /home/travis/src/hugo/hugolib/site_render.go:73 +0x199
  github.com/gohugoio/hugo/hugolib.(*Site).render()
      /home/travis/src/hugo/hugolib/site.go:1161 +0x8b
  github.com/gohugoio/hugo/hugolib.(*HugoSites).render()
      /home/travis/src/hugo/hugolib/hugo_sites_build.go:302 +0x9f0
  github.com/gohugoio/hugo/hugolib.(*HugoSites).Build.func4()
      /home/travis/src/hugo/hugolib/hugo_sites_build.go:121 +0x57
  runtime/trace.WithRegion()
      /home/travis/.gimme/versions/go1.12.2.linux.amd64/src/runtime/trace/annotation.go:137 +0x10b
  github.com/gohugoio/hugo/hugolib.(*HugoSites).Build()
      /home/travis/src/hugo/hugolib/hugo_sites_build.go:123 +0xa50
  github.com/gohugoio/hugo/hugolib.(*sitesBuilder).build()
      /home/travis/src/hugo/hugolib/testhelpers_test.go:440 +0x1a7
  github.com/gohugoio/hugo/hugolib.TestEmbeddedTemplates()
      /home/travis/src/hugo/hugolib/testhelpers_test.go:407 +0x2c8
  testing.tRunner()
      /home/travis/.gimme/versions/go1.12.2.linux.amd64/src/testing/testing.go:865 +0x163
==================
--- FAIL: TestEmbeddedTemplates (0.51s)
    testing.go:809: race detected during execution of test
larzza commented 5 years ago

@bep I’m curious... why do you think this is a Go bug?

bep commented 5 years ago

Because the data race (both read and write) is inside template.Execute:

https://godoc.org/html/template#Template.Execute

Which states that:

A template may be executed safely in parallel, although if parallel executions share a Writer the output may be interleaved.

larzza commented 5 years ago

Thanks, seems reasonable!

I get the race for my theme both when using Go 1.11 and 1.12 (only tested with latest Go patches though).

larzza commented 5 years ago

Just noticed you’ve been down this road before...

bep commented 5 years ago

It's a road with many side roads...

larzza commented 5 years ago

Indeed it is!

bep commented 5 years ago

We have always rendered in parallel.

bep commented 4 years ago

https://github.com/golang/go/issues/39807

andreasf commented 4 years ago

Related issue: "fatal error: concurrent map read and map write" #7293

Fix in template fork: "Fix data race in templating code" #7507

shiftgeist commented 3 years ago

Upstream https://github.com/golang/go/issues/20531 is closed again with https://github.com/golang/go/commit/d0dd26a88c019d54f22463daae81e785f5867565 fixing commit in master.

github-actions[bot] commented 8 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.