Fix data race in gitlab source cache package
The following discussion from !246 (merged) should be addressed:
-
@nolith started a discussion: (+1 comment) Here the race is deep inside the package
we make use of global variables and this test will alter
retrievalTimeout
when a goroutine from the previous one is still running.This will require extra effort to fix, but I think we should add the race detector now.
================== WARNING: DATA RACE Write at 0x000000e0d4f0 by goroutine 46: gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.TestResolve.func9() /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:247 +0x3e testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Previous read at 0x000000e0d4f0 by goroutine 44: gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Retriever).Retrieve() /builds/nolith/gitlab-pages/internal/source/gitlab/cache/retriever.go:22 +0x8d gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Entry).retrieveWithClient() /builds/nolith/gitlab-pages/internal/source/gitlab/cache/entry.go:92 +0xc5 Goroutine 46 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.TestResolve() /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:246 +0x1d5 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 44 (running) created at: gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Entry).Retrieve.func1() /builds/nolith/gitlab-pages/internal/source/gitlab/cache/entry.go:64 +0x67 sync.(*Once).Do() /usr/local/go/src/sync/once.go:44 +0xde gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Entry).Retrieve() /builds/nolith/gitlab-pages/internal/source/gitlab/cache/entry.go:64 +0xad gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.(*Cache).Resolve() /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache.go:89 +0x1ea gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.TestResolve.func8.1() /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:239 +0x76 gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.withTestCache() /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:89 +0x185 gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/cache.TestResolve.func8() /builds/nolith/gitlab-pages/internal/source/gitlab/cache/cache_test.go:238 +0xc7 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ==================