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

Crash with empty value of --repo_env #15430

Closed
layus opened this issue May 9, 2022 · 3 comments
Closed

Crash with empty value of --repo_env #15430

layus opened this issue May 9, 2022 · 3 comments
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug

Comments

@layus
Copy link
Contributor

layus commented May 9, 2022

Description of the bug:

When a --repo_env var lacks the value part, Bazel crashes instead of using the value of that variable from the environment.

Starting local Bazel server and connecting to it...
Loading: 0 packages loaded
FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node 'REPOSITORY_DIRECTORY:@debug' (requested by nodes 'IGNORED_PACKAGE_PREFIXES:@debug')
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:674)
	at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:382)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.NullPointerException: null value in entry: FOO=null
	at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:32)
	at com.google.common.collect.RegularImmutableMap.fromEntryArray(RegularImmutableMap.java:99)
	at com.google.common.collect.RegularImmutableMap.fromEntries(RegularImmutableMap.java:73)
	at com.google.common.collect.ImmutableMap.copyOf(ImmutableMap.java:460)
	at com.google.common.collect.ImmutableMap.copyOf(ImmutableMap.java:433)
	at com.google.devtools.build.lib.bazel.repository.starlark.StarlarkRepositoryFunction.fetch(StarlarkRepositoryFunction.java:174)
	at com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction.fetchRepository(RepositoryDelegatorFunction.java:415)
	at com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction.compute(RepositoryDelegatorFunction.java:349)
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:590)
	... 4 more

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

Create a trivial repository_rule that uses the env variable.

───────┬───────────────────────────────────────────────
       │ File: BUILD   <EMPTY>
       │ Size: 0 B
───────┴───────────────────────────────────────────────
───────┬───────────────────────────────────────────────
       │ File: main.bzl
       │ Size: 198 B
───────┼───────────────────────────────────────────────
   1   │ 
   2   │ def _dump_env(ctx):
   3   │     val = ctx.os.environ.get("FOO", "nothing")
   4   │     print("FOO", val)
   5   │     ctx.file("FOO", val)
   6   │ 
   7   │ 
   8   │ dump_env = repository_rule(
   9   │     implementation = _dump_env,
  10   │     local = True,
  11   │ )
  12   │ 
───────┴───────────────────────────────────────────────
───────┬───────────────────────────────────────────────
       │ File: WORKSPACE
       │ Size: 65 B
───────┼───────────────────────────────────────────────
   1   │ load("//:main.bzl", "dump_env")
   2   │ 
   3   │ dump_env(
   4   │     name = "debug",
   5   │ )
───────┴───────────────────────────────────────────────
bazel build @debug//:foo

Which operating system are you running Bazel on?

Linux (NixOS)

What is the output of bazel info release?

release 5.1.1- (@non-git)

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

Bazel 5.1.1, built with nix, on NixOS.

Not tested yet if this is nix/nixos specific.

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git

Have you found anything relevant by searching the web?

Seems like the feature is used to be broken: #12886

See also #8869

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

No response

@layus
Copy link
Contributor Author

layus commented May 9, 2022

Seems like the underlying library started refusing null entries while the code relies on them to encode the case where no value is passed and the real value must be taken from the environment.

@sgowroji sgowroji added type: bug team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. untriaged labels May 10, 2022
@layus
Copy link
Contributor Author

layus commented May 13, 2022

Oh, it seems my report lacks the most important part: the actual --repo_env=FOO flag.

You can change the command line to FOO=bar bazel build @debug//:test --repo_env=FOO, or use a .bazelrc like I did.

I had to deep clean everything before reproducing again:

bazel clean --expunge
bazel shutdown
rm -rf ~/.cache/bazel

@meteorcloudy meteorcloudy self-assigned this May 24, 2022
@meteorcloudy meteorcloudy added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels May 24, 2022
copybara-service bot pushed a commit that referenced this issue Jun 28, 2022
Fix and test for null value bug when using --repo_env
[Issue Link](#15430)

Closes #15618.

PiperOrigin-RevId: 457728307
Change-Id: I3d57ae4ac95de09215281bec51329b7baafd53af
This was referenced Jun 29, 2022
ckolli5 added a commit that referenced this issue Jul 5, 2022
Fix and test for null value bug when using --repo_env
[Issue Link](#15430)

Closes #15618.

PiperOrigin-RevId: 457728307
Change-Id: I3d57ae4ac95de09215281bec51329b7baafd53af

Co-authored-by: Googler <noreply@google.com>
@meteorcloudy
Copy link
Member

Fixed by ed886ee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug
Projects
None yet
Development

No branches or pull requests

4 participants