Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new gazelle v0.36.0 fails with Go sum mismatches #1774

Closed
tyler-french opened this issue Apr 4, 2024 · 10 comments · Fixed by #1782
Closed

new gazelle v0.36.0 fails with Go sum mismatches #1774

tyler-french opened this issue Apr 4, 2024 · 10 comments · Fixed by #1782

Comments

@tyler-french
Copy link
Contributor

What version of gazelle are you using?

https://github.com/bazelbuild/bazel-gazelle/releases/tag/v0.36.0

What version of rules_go are you using?

https://github.com/bazelbuild/rules_go/releases/tag/v0.46.0

What version of Bazel are you using?

7.1.1

Does this issue reproduce with the latest releases of all the above?

Yes

What operating system and processor architecture are you using?

Linux AMD 64

What did you do?

Darwin ARM 64

What did you expect to see?

Successful gazelle run

What did you see instead?

ERROR: An error occurred during the fetch of repository 'com_github_procyon_projects_chrono':
   Traceback (most recent call last):
	File "/private/var/tmp/_bazel_johankj/cf455b47f50dd837b297aa6fcdb2d775/external/bazel_gazelle/internal/go_repository.bzl", line 263, column 17, in _go_repository_impl
		fail("failed to fetch %s: %s" % (ctx.name, result.stderr))
Error in fail: failed to fetch com_github_procyon_projects_chrono: fetch_repo: resulting module with sum h1:l0VwRF053FgTUXw2dMwpHYBY9d0SuZOAmjSBOvdeO1Y=; expected sum h1:edOeKOW2eGP8j3gI6wQWzyoUM0njjuxOlbtpguIkXqQ=
ERROR: /Users/johankj/Uber/go-code-odin/WORKSPACE:68:26: fetching go_repository rule //external:com_github_procyon_projects_chrono: Traceback (most recent call last):
	File "/private/var/tmp/_bazel_johankj/cf455b47f50dd837b297aa6fcdb2d775/external/bazel_gazelle/internal/go_repository.bzl", line 263, column 17, in _go_repository_impl
		fail("failed to fetch %s: %s" % (ctx.name, result.stderr))
Error in fail: failed to fetch com_github_procyon_projects_chrono: fetch_repo: resulting module with sum h1:l0VwRF053FgTUXw2dMwpHYBY9d0SuZOAmjSBOvdeO1Y=; expected sum h1:edOeKOW2eGP8j3gI6wQWzyoUM0njjuxOlbtpguIkXqQ=
Analyzing: target //src/code.uber.internal/compute/foosbot:foosbot (462 packages loaded, 2947 targets configured)

However this is a pretty normal go_repository rule:

 go_repository(
        name = "com_github_procyon_projects_chrono",
        build_extra_args = ["-go_naming_convention_external=go_default_library"],
        build_file_generation = "on",
        build_file_proto_mode = "disable",
        importpath = "github.com/procyon-projects/chrono",
        sum = "h1:edOeKOW2eGP8j3gI6wQWzyoUM0njjuxOlbtpguIkXqQ=",
        version = "v1.0.0",
    )
@tyler-french
Copy link
Contributor Author

Might be related to: #1755

@fmeum
Copy link
Member

fmeum commented Apr 4, 2024

@scaiper Do you happen to see why this particular module would result in a different hash?

@scaiper
Copy link
Contributor

scaiper commented Apr 4, 2024

I've tried this exact version with sum = "h1:edOeKOW2eGP8j3gI6wQWzyoUM0njjuxOlbtpguIkXqQ=" and it worked. But we use Bzlmod, maybe there are some differences.
Also this project changed module name, in recent versions it is codnect.io/chrono, maybe it is somehow relevant.
I'll try to look at this issue tomorrow.

@scaiper
Copy link
Contributor

scaiper commented Apr 4, 2024

Can you confirm that this issue still occurs after bazel clean --expunge?

@scaiper
Copy link
Contributor

scaiper commented Apr 4, 2024

Are you using either GO_REPOSITORY_USE_HOST_CACHE or GO_REPOSITORY_USE_HOST_MODCACHE options? If you do, could you also try cleaning host module cache? It could be modified.

@tyler-french
Copy link
Contributor Author

We're only noticing this in a very specific environment, so we may be doing something weird. Will follow-up

@tyler-french
Copy link
Contributor Author

(cc @linzhp) It looks like the reason this is happening is because of our "sparse checkout" tooling. We have a feature to be able to checkout only a small part of our Monorepo (and all it's required deps, including external deps), which we copy over from a "full" work tree.

In this case, it looks like the sum of the downloaded archive matches the SUM in the go.sum file and go_repository rule, but at build time, the external directory's sum might be slightly different, as it only has the required packages for the current targets.

@scaiper
Copy link
Contributor

scaiper commented Apr 10, 2024

To be precise, it's not a build time verification. Verification is done in repository rule right after downloading and coping module to final location.
It should only differ if host module cache is in use and this cache is modified.

@tyler-french
Copy link
Contributor Author

tyler-french commented Apr 10, 2024

Hmm, it does look like we are using a local GOMODCACHE. I am curious if/why this would be getting corrupted.

@tyler-french
Copy link
Contributor Author

Created this PR: #1782
Some users have go mod cache's that are years old, and we have never verified them

If we start verifying them, I think it would be good to let them know that this might be the failure cause.

tyler-french added a commit that referenced this issue Apr 12, 2024
This failure was confusing to our users. We should make more clear error messages in cases when a `GOMODCACHE` might be corrupt.

Resolves #1774

Example failure:
```
ERROR: /home/user/go-code/WORKSPACE:69:26: fetching go_repository rule //external:com_github_bazelbuild_remote_apis: Traceback (most recent call last):
        File "/home/user/.cache/bazel/_bazel_tfrench/b97476d719d716accead0f2d5b93104f/external/bazel_gazelle/internal/go_repository.bzl", line 263, column 17, in _go_repository_impl
                fail("failed to fetch %s: %s" % (ctx.name, result.stderr))
Error in fail: failed to fetch com_github_bazelbuild_remote_apis: fetch_repo: resulting module with sum h1:xhO5v3Ac039HesaPqoVUwOy4WhRRJbmo9om245kp+AY=; expected sum h1:xhO5v3Ac039HesaPqoVUwOy4WhRRJbmo9om245kp+AY=, Please try clearing your module cache directory "/home/user/go-code/pkg/mod"
ERROR: Error computing the main repository mapping: no such package '@@com_github_bazelbuild_remote_apis//': failed to fetch com_github_bazelbuild_remote_apis: fetch_repo: resulting module with sum h1:xhO5v3Ac039HesaPqoVUwOy4WhRRJbmo9om245kp+AY=; expected sum h1:xhO5v3Ac039HesaPqoVUwOy4WhRRJbmo9om245kp+AY=, Please try clearing your module cache directory "/home/user/go-code/pkg/mod"
INFO: Build Event Protocol files produced successfully.
Computing main repo mapping: 
WARNING:Bazel failed with exit code 1
```
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 a pull request may close this issue.

3 participants