gohugoio / hugo

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

A field in a structure is sometimes protected by Mutex, but sometimes unprotected. #7222

Open BurtonQin opened 4 years ago

BurtonQin commented 4 years ago

What version of Hugo are you using (hugo version)?

master branch, commit c03ea2b66010d2996d652903cb8fa41e983e787f

What happened: A field in a structure is sometimes protected by Mutex, but sometimes unprotected. This may lead to data race. There are 2 such cases:

What you expected to happen: Data race

paskal commented 3 years ago

The only way to properly protect t.text (as it's used elsewhere after return) is to make a deep copy of it and return the pointer to that copy instead of the original: that's a cure worse than the disease, in my opinion, as it will complicate code for no clear benefit.

bep commented 3 years ago

This may lead to data race.

Only if it's read/write from multiple go routines at the same time.

  1. postTransform is, to my knowledge, always done in 1 thread and before the templates gets used.
  2. Any concurrency issue with t.text should be addressed in the source (Go stdlib).

Also, note that we have a fair amount of tests that run this code successfully with the -race flag enabled.