gohugoio / hugo

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

Data race in scratch.SetInMap #7230

Open bep opened 4 years ago

bep commented 4 years ago
Building sites … fatal error: concurrent map writes

goroutine 63 [running]:
runtime.throw(0x596c369, 0x15)
        /usr/local/go/src/runtime/panic.go:1112 +0x72 fp=0xc003917d60 sp=0xc003917d30 pc=0x4036372
runtime.mapassign_faststr(0x568c460, 0xc003886e40, 0xc0002f2635, 0x8, 0xc001a4f048)
        /usr/local/go/src/runtime/map_faststr.go:291 +0x3de fp=0xc003917dc8 sp=0xc003917d60 pc=0x4015b2e
github.com/gohugoio/hugo/common/maps.(*Scratch).SetInMap(0xc0039080e0, 0xc0002f262e, 0x4, 0xc0002f2635, 0x8, 0x558df40, 0xc001e0b760, 0x0, 0x0)
        /Users/bep/dev/go/gohugoio/hugo/common/maps/scratch.go:119 +0xe5 fp=0xc003917e18 sp=0xc003917dc8 pc=0x442ca35
runtime.call128(0xc002f6bbc0, 0xc003415248, 0xc003022fa0, 0x3800000048)
        /usr/local/go/src/runtime/asm_amd64.s:541 +0x52 fp=0xc003917ea8 sp=0xc003917e18 pc=0x40670a2
reflect.Value.call(0x57475e0, 0xc0039080e0, 0x1613, 0x59092b0, 0x4, 0xc003022f50, 0x3, 0x3, 0xc001e0b760, 0x97, ...)
        /usr/local/go/src/reflect/value.go:460 +0x8ab fp=0xc0039180c0 sp=0xc003917ea8 pc=0x40c908b
reflect.Value.Call(0x57475e0, 0xc0039080e0, 0x1613, 0xc003022f50, 0x3, 0x3, 0x5681000, 0xc0039181b0, 0xc0039181b0)
        /usr/local/go/src/reflect/value.go:321 +0xb4 fp=0xc003918140 sp=0xc0039180c0 pc=0x40c8594
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.safeCall(0x57475e0, 0xc0039080e0, 0x1613, 0xc003022f50, 0x3, 0x3, 0x0, 0x0, 0x0, 0x0, ...)
        /Users/bep/dev/go/gohugoio/hugo/tpl/internal/go_templates/texttemplate/funcs.go:352 +0xbd fp=0xc0039181c0 sp=0xc003918140 pc=0x4a437dd
github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate.(*state).evalCall(0xc003918db8, 0x558df40, 0xc001e

/cc @regisphilibert

bep commented 4 years ago

Looking at the case in question, I'm hesitant to add a general fix for this -- as it would hurt performance for the common case.

We may consider adding some copy functions so you can do scratch.Get "data" | shallowCopy or something.

regisphilibert commented 4 years ago

Or... https://github.com/gohugoio/hugo/issues/7232