diff options
author | Bjørn Erik Pedersen <[email protected]> | 2018-02-13 21:45:51 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2018-02-15 09:41:29 +0100 |
commit | d8fdffb55268464d54558d6f9cd3874b612dc7c7 (patch) | |
tree | 433266be0c7d178fcc6b1868712b00eb9173b408 /resource/image.go | |
parent | 2851af0225cdf6c4e47058979cd22949ed6d1fc0 (diff) | |
download | hugo-d8fdffb55268464d54558d6f9cd3874b612dc7c7.tar.gz hugo-d8fdffb55268464d54558d6f9cd3874b612dc7c7.zip |
resource: Fix multi-threaded image processing issue
When doing something like this with the same image from a partial used in, say, both the home page and the single page:
```bash
{{ with $img }}
{{ $big := .Fill "1024x512 top" }}
{{ $small := $big.Resize "512x" }}
{{ end }}
```
There would be timing issues making Hugo in some cases try to process the same image with the same instructions in parallel.
You would experience errors of type:
```bash
png: invalid format: not enough pixel data
```
This commit works around that by adding a mutex per image. This should also improve the performance, sligthly, as it avoids duplicate work.
The current workaround before this fix is to always operate on the original:
```bash
{{ with $img }}
{{ $big := .Fill "1024x512 top" }}
{{ $small := .Fill "512x256 top" }}
{{ end }}
```
Fixes #4404
Diffstat (limited to 'resource/image.go')
-rw-r--r-- | resource/image.go | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/resource/image.go b/resource/image.go index 1914b3c04..208a0e9fb 100644 --- a/resource/image.go +++ b/resource/image.go @@ -112,6 +112,9 @@ type Image struct { copyToDestinationInit sync.Once + // Lock used when creating alternate versions of this image. + createMu sync.Mutex + imaging *Imaging hash string |