bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
22.95k stars 4.02k forks source link

Bazel cquery crash on //external:all-targets #17608

Open linzhp opened 1 year ago

linzhp commented 1 year ago

Description of the bug:

Bazel would crash when running bazel cquery //external:all-targets:

FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node 'ConfiguredTargetKey{label=//external:WORKSPACE, config=null}' (requested by nodes )
    at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:591)
    at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:375)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Caused by: java.util.NoSuchElementException: No value present
    at java.base/java.util.Optional.get(Optional.java:148)
    at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createConfiguredTarget(ConfiguredTargetFactory.java:254)
    at com.google.devtools.build.lib.skyframe.SkyframeBuildView.createConfiguredTarget(SkyframeBuildView.java:1193)
    at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.createConfiguredTarget(ConfiguredTargetFunction.java:328)
    at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.compute(ConfiguredTargetFunction.java:245)
    at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:501)
    ... 7 more

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

In a Bazel repo, run bazel cquery //external:all-targets

Which operating system are you running Bazel on?

macOS

What is the output of bazel info release?

release 6.0.0-homebrew

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

No response

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

No response

Have you found anything relevant by searching the web?

No response

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

No response

gregestren commented 1 year ago

Assigned to @katre for triage.

katre commented 1 year ago

This happens with any cquery on //external, because the magic external package has a source root of Optional.empty.

I'm going to keep investigating a fix.

katre commented 1 year ago

The crash was added in d0b2d68783c1e23cc6bfa58b709aa8288ca3f6fe, because ConfiguredTargetFactory is accessing the source root without checking whether the Optional is present.

This crash isn't strictly due to cquery, I'm reassigning to @c-parsons who wrote the commit.

github-actions[bot] commented 1 month ago

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

c-parsons commented 1 month ago

This is still an issue we'd like to address, just has been deprioritized. At the very least, Bazel should not error with a crash (and stack trace) given such an input.