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

Bazel crashes when using bzlmod and a registry with an incorrect bazel_registry.json file #14437

Closed
danielmachlab opened this issue Dec 15, 2021 · 3 comments
Assignees
Labels
area-Bzlmod Bzlmod-specific PRs, issues, and feature requests good first issue help wanted Someone outside the Bazel team could own this team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug

Comments

@danielmachlab
Copy link

danielmachlab commented Dec 15, 2021

Description of the problem / feature request:

Bazel crashes due to an internal error when using a bzlmod registry that doesn't correctly specify a bazel_registry.json file. The stack-trace printed by Bazel when it crashes is included in the last section below.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

To demonstrate this bug, I created a fork of the bazel-central-repository and made a single commit that deletes the contents of the bazel_registry.json file. I also created an bazelmod_example repository that has a dependency on zlib.

To reproduce the bug:

  1. Install bazelisk
  2. git clone https://github.com/danielmachlab/bzlmod_example
  3. bazelisk build src:hello-world --experimental_enable_bzlmod to demonstrate the example works when using the bazel-central-repository
  4. bazelisk build src:hello-world --experimental_enable_bzlmod --registry https://danielmachlab.github.io/bazel-central-registry/ to reproduce the bug by using the forked version of the bazel-central-repository, which contained an empty bazel_registry.json file

What operating system are you running Bazel on?

MacOS Big Sur 11.5.2

What's the output of bazel info release?

2021/12/15 15:52:43 Using unreleased version at commit 4c6e324dfab9444fc51b9fb3f5074a01889725e1
Starting local Bazel server and connecting to it...
development version

If bazel info release returns "development version" or "(@non-git)", tell us how you built Bazel.

I am using bazelisk with a .bazeliskrc file containing:

USE_BAZEL_VERSION=last_green

Have you found anything relevant by searching the web?

I haven't found anything specific to this issue, but I have been referencing the following resources:
bzlmod user guide
Bazel External Dependencies Overhaul Google Doc

Any other information, logs, or outputs that you want to share?

This is the stack trace printed after Bazel crashes:

machlabda@machlabda-a01 bzlmod_example % bazel build src:hello-world --registry https://danielmachlab.github.io/bazel-central-registry/ 
2021/12/15 15:50:14 Using unreleased version at commit 4c6e324dfab9444fc51b9fb3f5074a01889725e1
Analyzing: target //src:hello-world (0 packages loaded, 0 targets configured)
FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node 'BZLMOD_REPO_RULE:zlib.1.2.11' (requested by nodes 'REPOSITORY_DIRECTORY:@zlib.1.2.11')
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:667)
        at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:382)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
Caused by: java.lang.NullPointerException
        at java.base/java.util.Objects.requireNonNull(Unknown Source)
        at java.base/java.util.Optional.<init>(Unknown Source)
        at java.base/java.util.Optional.of(Unknown Source)
        at com.google.devtools.build.lib.bazel.bzlmod.IndexRegistry.grabJson(IndexRegistry.java:118)
        at com.google.devtools.build.lib.bazel.bzlmod.IndexRegistry.getRepoSpec(IndexRegistry.java:125)
        at com.google.devtools.build.lib.bazel.bzlmod.BzlmodRepoRuleHelperImpl.checkRepoFromBazelModules(BzlmodRepoRuleHelperImpl.java:83)
        at com.google.devtools.build.lib.bazel.bzlmod.BzlmodRepoRuleHelperImpl.getRepoSpec(BzlmodRepoRuleHelperImpl.java:56)
        at com.google.devtools.build.lib.skyframe.BzlmodRepoRuleFunction.compute(BzlmodRepoRuleFunction.java:129)
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:591)
        ... 7 more
@Wyverald Wyverald self-assigned this Dec 15, 2021
@Wyverald
Copy link
Member

Ah yeah, we didn't really program defensively enough here... Thanks for the report!

@Wyverald Wyverald added the team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. label Dec 15, 2021
@alexeagle
Copy link
Contributor

I also noticed a bazel crash when the json file (source or metadata) for a module contains a trailing comma

@Wyverald Wyverald added good first issue help wanted Someone outside the Bazel team could own this labels Dec 20, 2021
@Wyverald Wyverald added the area-Bzlmod Bzlmod-specific PRs, issues, and feature requests label Jan 24, 2022
bazel-io pushed a commit that referenced this issue Mar 24, 2022
[Fixes](#14437)

Get rid of new lines in `bazel_registry.json` and return an `Optional.empty()` aka registry descriptor without mirrors and throw an IOException for malformed JSON to stick to official json.org specs

Closes #15109.

PiperOrigin-RevId: 436992309
ckolli5 added a commit that referenced this issue May 9, 2022
[Fixes](#14437)

Get rid of new lines in `bazel_registry.json` and return an `Optional.empty()` aka registry descriptor without mirrors and throw an IOException for malformed JSON to stick to official json.org specs

Closes #15109.

PiperOrigin-RevId: 436992309

Co-authored-by: Thomas Zayouna <[email protected]>
@meteorcloudy
Copy link
Member

Fixed by ac21910

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Bzlmod Bzlmod-specific PRs, issues, and feature requests good first issue help wanted Someone outside the Bazel team could own this team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug
Projects
None yet
Development

No branches or pull requests

5 participants