bazelbuild / rules_go

Go rules for Bazel
Apache License 2.0
1.36k stars 635 forks source link

GoToolchainBinaryBuild leaves temp gopath dir (linux), or uploads to cache (windows) #3884

Closed hauserx closed 3 months ago

hauserx commented 3 months ago

What version of rules_go are you using?

0.46.0

What version of gazelle are you using?

0.35.0

What version of Bazel are you using?

6.4

What operating system and processor architecture are you using?

Linux & Windows

What did you do?

Build anything with rules_go.

What did you see instead?

Each GoToolchainBinaryBuild execution leaves 2 entries like /tmp/tmp.CGmiYEaaeP/ under linux. Those correspond to throwaway cache created by mktemp -d that is never cleaned up: https://github.com/bazelbuild/rules_go/blob/d45e218910fbecb00867e3a4dde3fe14d4a1e00a/go/private/rules/binary.bzl#L462

Under Windows the same rule uses declare_directory to create space for cache and returns the declared directory from the rule, what causes uploading temporary gocache entries to remote cache and subsequent downloads. https://github.com/bazelbuild/rules_go/blob/d45e218910fbecb00867e3a4dde3fe14d4a1e00a/go/private/rules/binary.bzl#L440

Cache contains ~500 files / 50MB, which are not really problematic numbers as those action usually do not execute often (maybe other than in CI), but still those temporary files should be cleaned up.

fmeum commented 3 months ago

That assessment looks entirely correct.

Would you be interested in submitting a PR to fix one or both issues? Happy to review it!