Skip to content

core: support GODEBUG as system env var + disable go mod index in CI tests - #8470

Merged
sipsma merged 1 commit into
dagger:mainfrom
sipsma:locked-go-sdk-caches
Sep 19, 2024
Merged

sipsma merged 1 commit into
dagger:mainfrom
sipsma:locked-go-sdk-caches

Conversation

@sipsma

@sipsma sipsma commented Sep 16, 2024 •

Copy link
Copy Markdown
Contributor

Trying out a possible mitigation to #8031 (which is pending on an upstream go issue).

In a previous iteration, this PR was changing the go cache volume mount mode, but that seemed to have too many performance deficiencies (see comment trail on this PR below).

Disabling the go mod index seems more promising, so going with that now.


GODEBUG=goindex=0 is an undocumented feature flag that disabled Go's
internal module index. In an upstream issue we opened with Go around a
bug in build caching that's impacting us, they used it to workaround the
bug.

This change thus adds support for GODEBUG as a system env var (similar
to our support for GOPROXY) and uses that to set goindex=0 just in our
CI test suite for now.

This bug seems to only happen under extreme use cases such as our CI
where we're running many, many go module builds, which is why this
change is only being used in our CI so far (as opposed to setting
GODEBUG=goindex=0 for all production users by default).

If this ends up impacting real-world users and we get confirmation from
the Go devs that setting this feature flag doesn't cause any subtle
problems, we can consider setting it by default too. Hopefully though
the upstream bug is just fixed and we can undo all this.

Signed-off-by: Erik Sipsma [email protected]

@sipsma

sipsma commented Sep 16, 2024

Copy link
Copy Markdown
Contributor Author

Hmm... all the CI test workflows timed out with changing the mode to Locked, so I'm gonna rule that out as non-viable in terms of the performance impact for now.

I will try mode Private instead

@sipsma

sipsma commented Sep 18, 2024

Copy link
Copy Markdown
Contributor Author

There does seem to be meaningful slowdown with Private cache volume mode, though not as devastating as with Locked (some workflows seem like a minute slower, though noisy so hard to really tell yet).

@rajatjindal had the good suggestion to try disabling the module index as go devs did in the upstream issue (golang/go#69179 (comment)) so will give that a shot too to see what the practical impact is

@sipsma

sipsma commented Sep 18, 2024

Copy link
Copy Markdown
Contributor Author

Hm disabling the module index doesn't appear to have much effect on the runtime across a few runs so far 🤷‍♂️🎉

I asked the go devs what the implications are of GODEBUG=goindex=0 in the upstream issue; it appears to be an undocumented setting (unless my googling is failing me).

I'm a little wary of setting undocumented feature-flags in our production code, but we could make this a system env var (similar to our existing support for GOPROXY) and just set it in our CI for now?

I'll setup the plumbing for that here and do some more re-runs while waiting to hear back from them.

GODEBUG=goindex=0 is an undocumented feature flag that disabled Go's
internal module index. In an upstream issue we opened with Go around a
bug in build caching that's impacting us, they used it to workaround the
bug.

This change thus adds support for GODEBUG as a system env var (similar
to our support for GOPROXY) and uses that to set goindex=0 just in our
CI test suite for now.

This bug seems to only happen under extreme use cases such as our CI
where we're running many, many go module builds, which is why this
change is only being used in our CI so far (as opposed to setting
GODEBUG=goindex=0 for all production users by default).

If this ends up impacting real-world users and we get confirmation from
the Go devs that setting this feature flag doesn't cause any subtle
problems, we can consider setting it by default too. Hopefully though
the upstream bug is just fixed and we can undo all this.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
sipsma force-pushed the locked-go-sdk-caches branch from be317ae to 3845357 Compare September 19, 2024 00:37
@sipsma sipsma changed the title engine: change go sdk cache mounts to be locked mode core: support GODEBUG as system env var + disable go mod index in CI tests Sep 19, 2024
@rajatjindal

Copy link
Copy Markdown
Contributor

:shipit:

@sipsma

sipsma commented Sep 19, 2024

Copy link
Copy Markdown
Contributor Author

I'll keep pressing re-run when I open this tab, but I've done a bunch of re-runs now without any occurrence of the flake and without any noticeable slowdown, so will take out of draft.

Would be nice to hear back from the go devs on my question about the implications of disabling the module index but I think since this change is scoped to purely our CI tests I'd be okay merging at this point, let me know if anyone disagrees.

@sipsma
sipsma marked this pull request as ready for review September 19, 2024 02:02
@sipsma
sipsma requested review from jedevc and vito September 19, 2024 02:02
@jedevc

jedevc commented Sep 19, 2024

Copy link
Copy Markdown
Contributor

Yeah, glancing through the source code for the mod index (which is wayyyy more complex than I have time to dive into right now), it's just a cache for https://pkg.go.dev/go/build#Context.Import - if the cache is disabled, we just fetch this data from the filesystem each time.

If we don't see a meaningful performance drop in the test runtime, no objection here, since the flakes are reasonably blocking - though obviously let's follow the upstream issue and help out where we can.


One thing that did stand out weirdly to me though: https://github.com/golang/go/blob/64a5d1d7de14ad74b1a77614de0e17c659ef12b6/src/cmd/go/internal/modindex/read.go#L73-L77

This feels very very similar to the case we saw for uv in #7662 (comment). Because everything is mounted at /src (the value of goSDKUserModContextDirPath), then I guess it's possible that we produce a ton of similar hashes? And then potentially something gets into a bad state from there (the docs for protect/unprotect do state that it might not be used for trivial accesses?).

@sipsma WDYT about trying our python fix for go, and seeing if that improves the flakes? That feels potentially a bit less invasive, and also if it is that, would help narrow down the go investigation as well?

Approving regardless though, will let you make the call here!

@sipsma

sipsma commented Sep 19, 2024

Copy link
Copy Markdown
Contributor Author

@jedevc good find, that's definitely suspicious! I think what I'll do is merge this one as is and open a follow-up PR where I try replacing this approach with that one. The main reasons being that A) I'd like to get a potential fix out ASAP and B) I think the other approach actually is (debatably) more invasive in that it's a meaningful change to the production code (whereas this one does it in such a way that only our test suite will have the module index disabled for now).

@sipsma
sipsma merged commit 0cae0be into dagger:main Sep 19, 2024
eunomie pushed a commit to eunomie/dagger that referenced this pull request Sep 22, 2026
Normalized Git trees can keep the same package paths, file sizes and mtimes across different source contents. Go then reuses a stale import index from the shared GOCACHE, even when source bytes and go.mod are correct.

Extend the goindex=0 mitigation from dagger#8470 to Go.Env, including the outer dev-engine build. Preserve existing GODEBUG options and shared compiled-artifact and module-download caches. See dagger#8031 and golang/go#69179.

Signed-off-by: Erik Sipsma <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants