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

Server crash when duplicate labels given to ctx.expand_location #14681

Closed
illicitonion opened this issue Feb 1, 2022 · 5 comments
Closed

Server crash when duplicate labels given to ctx.expand_location #14681

illicitonion opened this issue Feb 1, 2022 · 5 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: bug

Comments

@illicitonion
Copy link
Contributor

Description of the problem / feature request:

If a label appears twice in the targets list of a call to ctx.expand_location, the server crashes with java.lang.IllegalArgumentException: Multiple entries with same key.

Either the duplicate should be ignored, or the duplication should be forbidden by the API and a friendly error given.

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

This rule:

def _r_impl(ctx):
    out = ctx.actions.declare_file(ctx.label.name)

    ctx.actions.write(
        output = out,
        content = ctx.expand_location(ctx.attr.template_string, ctx.attr.deps + ctx.attr.deps),
    )   

    return [
        DefaultInfo(files = depset([out])),
    ]   

r = rule(
    implementation = _r_impl,
    attrs = { 
        "template_string": attr.string(),
        "deps": attr.label_list(),
    },  
)

Instantiated thus:

load("//:rule.bzl", "r")
    
r(  
    name = "write", 
    template_string = "Hello",
    deps = ["@bazel_tools//tools/cpp:empty"],
)

What operating system are you running Bazel on?

macOS

What's the output of bazel info release?

release 5.0.0

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

Stack trace from failure:

FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node 'ConfiguredTargetKey{label=//:write, config=BuildConfigurationValue.Key[63684d86ff47f33398646ba0e3860d9ff1fcad99873cee4f2aec407f500adbdd]}' (requested by nodes )
	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.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: net.starlark.java.eval.Starlark$UncheckedEvalException: IllegalArgumentException thrown during Starlark evaluation (//:write)
	at <starlark>.expand_location(<builtin>:0)
	at <starlark>._r_impl(/Users/dwagnerhall/tmp/bazelplay/rule.bzl:6)
Caused by: java.lang.IllegalArgumentException: Multiple entries with same key: @bazel_tools//tools/cpp:empty=[] and @bazel_tools//tools/cpp:empty=[]
	at com.google.common.collect.ImmutableMap.conflictException(ImmutableMap.java:210)
	at com.google.common.collect.ImmutableMap.checkNoConflict(ImmutableMap.java:204)
	at com.google.common.collect.RegularImmutableMap.checkNoConflictInKeyBucket(RegularImmutableMap.java:146)
	at com.google.common.collect.RegularImmutableMap.fromEntryArray(RegularImmutableMap.java:109)
	at com.google.common.collect.ImmutableMap$Builder.build(ImmutableMap.java:389)
	at com.google.devtools.build.lib.analysis.starlark.StarlarkRuleContext.makeLabelMap(StarlarkRuleContext.java:1102)
	at com.google.devtools.build.lib.analysis.starlark.StarlarkRuleContext.expandLocation(StarlarkRuleContext.java:902)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at net.starlark.java.eval.MethodDescriptor.call(MethodDescriptor.java:162)
	at net.starlark.java.eval.BuiltinFunction.fastcall(BuiltinFunction.java:77)
	at net.starlark.java.eval.Starlark.fastcall(Starlark.java:619)
	at net.starlark.java.eval.Eval.evalCall(Eval.java:672)
	at net.starlark.java.eval.Eval.eval(Eval.java:489)
	at net.starlark.java.eval.Eval.evalCall(Eval.java:630)
	at net.starlark.java.eval.Eval.eval(Eval.java:489)
	at net.starlark.java.eval.Eval.exec(Eval.java:271)
	at net.starlark.java.eval.Eval.execStatements(Eval.java:82)
	at net.starlark.java.eval.Eval.execFunctionBody(Eval.java:66)
	at net.starlark.java.eval.StarlarkFunction.fastcall(StarlarkFunction.java:191)
	at net.starlark.java.eval.Starlark.fastcall(Starlark.java:619)
	at com.google.devtools.build.lib.analysis.starlark.StarlarkRuleConfiguredTargetUtil.buildRule(StarlarkRuleConfiguredTargetUtil.java:98)
	at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createRule(ConfiguredTargetFactory.java:353)
	at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createConfiguredTarget(ConfiguredTargetFactory.java:188)
	at com.google.devtools.build.lib.skyframe.SkyframeBuildView.createConfiguredTarget(SkyframeBuildView.java:1108)
	at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.createConfiguredTarget(ConfiguredTargetFunction.java:980)
	at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.compute(ConfiguredTargetFunction.java:368)
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:590)
	at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:382)
	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)
illicitonion added a commit to illicitonion/rules_rust that referenced this issue Feb 1, 2022
illicitonion added a commit to illicitonion/rules_rust that referenced this issue Feb 1, 2022
UebelAndre pushed a commit to bazelbuild/rules_rust that referenced this issue Feb 1, 2022
@brandjon brandjon added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed untriaged labels Feb 10, 2022
cfredric pushed a commit to cfredric/rules_rust that referenced this issue Feb 16, 2022
@varungandhi-src
Copy link

I wonder if this is the same crash as the one I'm seeing in this branch: sourcegraph/scip-ruby@49be984 (includes full error + build step)

In my case, the keys are printed differently though:

Caused by: java.lang.IllegalArgumentException: Multiple entries with same key: TEST_NAME=//test/scip/repos:shopify-api-ruby and TEST_NAME=shopify-api-ruby

I haven't tried minimizing that one, because I wasn't even sure where to start minimizing. 😬

@illicitonion
Copy link
Contributor Author

@varungandhi-src I suspect that's related to the env attribute rather than ctx.expand_location - could you post your full stack trace? It's currently truncated in library code before the code hits any bazel code.

@varungandhi-src
Copy link

@illicitonion I've filed #16094 with a minimal reproducer, I think it's a different issue.

Copy link

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.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Apr 27, 2024
@illicitonion
Copy link
Contributor Author

This was fixed in 3db362c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: bug
Projects
None yet
Development

No branches or pull requests

5 participants