native-build-tools icon indicating copy to clipboard operation
native-build-tools copied to clipboard

Sporadic Gradle failure: access-filter.json already exists

Open jeanbisutti opened this issue 1 year ago • 1 comments

The Native Build Tools Gradle plugin is used in the OpenTelemetry Java instrumentation Github repository.

Sometimes the plugin fails. A failure report example: https://ge.opentelemetry.io/s/2rq2vt7d7bsng/failure?expanded-stacktrace=WyIwLTEtMi0zLTQiXQ#1

The root case:

Caused by: java.nio.file.FileAlreadyExistsException: /tmp/agent-config
at org.graalvm.buildtools.agent.AgentConfiguration.addDefaultAccessFilter(AgentConfiguration.java:156)	
at org.graalvm.buildtools.agent.AgentConfiguration.getAgentCommandLine(AgentConfiguration.java:99)	
at org.gradle.api.internal.provider.ValueSupplier$Present.transform(ValueSupplier.java:519) 

The problem seems to come from the recent changes in the AgentConfiguration class, and released in 0.10.3.

The native agent is not enabled from our build.gradle.kts file or a command line (./gradlew -Pagent). Perhaps some code related to the agent could only be executed if the agent is enabled.

Would you have any workaround to recommend?

Thanks.

jeanbisutti avatar Sep 30 '24 12:09 jeanbisutti

Please use 0.10.2 version util we fix the problem. Thanks for reporting!

dnestoro avatar Oct 07 '24 14:10 dnestoro

I have the same kind of issue with the version 0.10.4. The processAot tasks is run in the context of a multi project Gradle build wih parallel feature enabled. It seems to be not supported. Can you confirm @dnestoro ?

Caused by: org.gradle.api.internal.provider.AbstractProperty$PropertyQueryException: Failed to calculate the value of property 'agentOptions'.
	at org.gradle.api.internal.provider.AbstractProperty.finalizeNow(AbstractProperty.java:[284](https://gitlab.arhs-developments.com/BPC/acceptorpsp/acceptor-psp-transaction-engine/-/jobs/4750122#L284))
	at org.gradle.api.internal.provider.AbstractProperty.lambda$beforeRead$0(AbstractProperty.java:276)
	at org.gradle.api.internal.provider.ValueState.finalizeOnReadIfNeeded(ValueState.java:139)
	at org.gradle.api.internal.provider.AbstractProperty.beforeRead(AbstractProperty.java:276)
	at org.gradle.api.internal.provider.AbstractProperty.beforeRead(AbstractProperty.java:268)
	at org.gradle.api.internal.provider.AbstractProperty.calculateOwnValue(AbstractProperty.java:162)
	at org.gradle.api.internal.provider.AbstractMinimalProvider.getOrNull(AbstractMinimalProvider.java:105)
	at org.gradle.api.internal.provider.ProviderResolutionStrategy$1.resolve(ProviderResolutionStrategy.java:27)
	at org.gradle.util.internal.DeferredUtil.unpack(DeferredUtil.java:59)
	at org.gradle.util.internal.DeferredUtil.unpackOrNull(DeferredUtil.java:49)
	at org.gradle.api.internal.tasks.properties.InputParameterUtils.prepareInputParameterValue(InputParameterUtils.java:38)
	at org.gradle.api.internal.tasks.properties.InputParameterUtils.prepareInputParameterValue(InputParameterUtils.java:30)
	... 98 more
Caused by: java.lang.RuntimeException: Cannot add default access-filter.json
	at org.graalvm.buildtools.agent.AgentConfiguration.addDefaultAccessFilter(AgentConfiguration.java:180)
	at org.graalvm.buildtools.agent.AgentConfiguration.getAgentCommandLine(AgentConfiguration.java:101)
	at org.gradle.api.internal.provider.ValueSupplier$Present.transform(ValueSupplier.java:519)
	at org.gradle.api.internal.provider.TransformBackedProvider.mapValue(TransformBackedProvider.java:91)
	at org.gradle.api.internal.provider.TransformBackedProvider.calculateOwnValue(TransformBackedProvider.java:82)
	at org.gradle.api.internal.provider.AbstractMinimalProvider.calculateValue(AbstractMinimalProvider.java:115)
	at org.gradle.api.internal.provider.Collectors$ElementsFromCollectionProvider.collectEntries(Collectors.java:280)
	at org.gradle.api.internal.provider.AbstractCollectionProperty$CollectingSupplier.calculateValue(AbstractCollectionProperty.java:500)
	at org.gradle.api.internal.provider.AbstractCollectionProperty.finalValue(AbstractCollectionProperty.java:311)
	at org.gradle.api.internal.provider.AbstractCollectionProperty.finalValue(AbstractCollectionProperty.java:79)
	at org.gradle.api.internal.provider.AbstractProperty.finalizeNow(AbstractProperty.java:281)
	... 109 more
Caused by: java.nio.file.FileAlreadyExistsException: /tmp/agent-config/access-filter_71_173383205
	at org.graalvm.buildtools.agent.AgentConfiguration.addDefaultAccessFilter(AgentConfiguration.java:169)
	... 119 more

ghilainm avatar Dec 10 '24 12:12 ghilainm

It seems task are really run in // at the same millisecond :).

            long pid = ProcessHandle.current().pid();
            long time = System.currentTimeMillis();
            Path tmpAccessFilter = agentDir.resolve(ACCESS_FILTER_PREFIX + '_' + pid  + '_' + time  + '_' + ACCESS_FILTER_SUFFIX);
            Files.copy(accessFilterData, tmpAccessFilter);

ghilainm avatar Dec 10 '24 12:12 ghilainm

It seems task are really run in // at the same millisecond :).

Can you please replace milliseconds with nanoseconds in the current implementation and run your tests again to see if the problem still occurs?

dnestoro avatar Dec 10 '24 14:12 dnestoro

Hey @jeanbisutti @ghilainm I recently merged a fix for this issue. Can you try if it resolves the problem on your projects?

Since it is already on master, you can build the plugin locally (see this) and apply locally built plugin to your project.

dnestoro avatar Jan 14 '25 10:01 dnestoro

@dnestoro I have not reproduced the issue locally. The issue was only observed in a CI. Do you have the possibility to publish a snapshot?

jeanbisutti avatar Jan 14 '25 11:01 jeanbisutti

@jeanbisutti unfortunately, we don't have possibility to publish snapshots. Let's wait for standard release then, and see if the issue is solved.

Please keep me updated if the issue gets resolved with the incoming release.

dnestoro avatar Jan 14 '25 12:01 dnestoro

@dnestoro Sorry have no time to test that. Can't easily reproduce sporadic issue. But I will upgrade to next version and check if the issue still happens.

ghilainm avatar Jan 14 '25 13:01 ghilainm

@ghilainm thanks! I hope next version (0.10.5) will be released in the incoming weeks

dnestoro avatar Jan 14 '25 13:01 dnestoro

@jeanbisutti @ghilainm can you please check if the error still occurs with the latest (0.10.5) release?

I will close this ticket. Feel free to reopen it if you experience the same failure with the new Native Build Tools version

dnestoro avatar Feb 13 '25 09:02 dnestoro