]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
resources: Fix race condition in test helper
authorSimon Heimlicher <simon.github@heimlicher.com>
Sat, 24 Jan 2026 14:41:29 +0000 (15:41 +0100)
committerGitHub <noreply@github.com>
Sat, 24 Jan 2026 14:41:29 +0000 (15:41 +0100)
The fetchResourceForSpec function was reusing a single ReadSeekCloser
across multiple goroutines, causing a race condition when
TestImageTransformConcurrent runs with imageProcWorkers > 1.

This was exposed by commit e569dd59a ("Misc webp performance work")
which increased imageProcWorkers from 1 to 2.

Fix by creating a new reader on each call to the open function.

Fixes race condition causing segfault on Apple Silicon.

Co-authored-by: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
resources/testhelpers_test.go

index 60cfae0c520b8301a71313a509270bb1864e5dfa..7ba71f21de1114349101b3751156e5c71cf4eccc 100644 (file)
@@ -113,7 +113,11 @@ func fetchImageForSpec(spec *resources.Spec, c *qt.C, name string) images.ImageR
 func fetchResourceForSpec(spec *resources.Spec, c *qt.C, name string, targetPathAddends ...string) resource.ContentResource {
        b, err := os.ReadFile(filepath.FromSlash("testdata/" + name))
        c.Assert(err, qt.IsNil)
-       open := hugio.NewOpenReadSeekCloser(hugio.NewReadSeekerNoOpCloserFromBytes(b))
+       // Create a new reader each time to avoid race conditions when multiple
+       // goroutines access the same resource concurrently.
+       open := func() (hugio.ReadSeekCloser, error) {
+               return hugio.NewReadSeekerNoOpCloserFromBytes(b), nil
+       }
        targetPath := name
        base := "/a/"
        r, err := spec.NewResource(resources.ResourceSourceDescriptor{