Skip to content

Understand Gradle 4.8 test failure around setup of security policies  #31324

@alpar-t

Description

@alpar-t

With Gradle 4.8 running on JDK 10 this happens (reformatted for readability):

java.lang.RuntimeException: unable to install test security manager
	at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:170)
	at org.elasticsearch.test.ESTestCase.<clinit>(ESTestCase.java:197)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:374)
	at com.carrotsearch.randomizedtesting.RandomizedRunner$2.run(RandomizedRunner.java:592)
Caused by: java.lang.IllegalStateException: codebase property already set: codebase.plugin-classloader -> 
file:/home/alpar/work/elastic/elasticsearch_master_ci/libs/plugin-classloader/build/distributions/plugin-classloader-7.0.0-alpha1-SNAPSHOT.jar, cannot set to 
file:/home/alpar/work/elastic/elasticsearch_master_ci/libs/plugin-classloader/build/distributions/plugin-classloader-7.0.0-alpha1-SNAPSHOT.jar
	at org.elasticsearch.bootstrap.Security.readPolicy(Security.java:233)
	at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:145)
	... 4 more

then most other tests fail with something like:

Exception in thread "Thread-3" java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.test.ESTestCase
    at java.base/java.lang.Thread.run(Thread.java:844)

The reading of policies from Security is done trough a static {} block in BootstrapForTesting which should guarantee that it is only initialized once. There doesn't seem to be any other code paths that exercise this, the only time Security.readPolicy is in BootstrapForTesting and Bootstrap that starts Elasticsearch, even if the tests were to do that, it doesn't have a chance to run before the tests are bootstrap.

It must be some strange intimacy between Gradle 4.8 and JDK 10 OpenJDK Runtime Environment (build 10.0.1+10) in my case, as the issue only reproduces with:
./gradlew clean check
It does not reproduce with:

  • ./gradlew :server:test
  • ./gradlew :server:test ran 100 times
  • Gradle 4.7
  • Gradle 4.8 with JDK 11ea (OpenJDK Runtime Environment 18.9 (build 11-ea+17))

Gradle seems to change the order of tasks a lot and will run many other tasks, including some tests before the :server:tests ( which probably doesn't make sense ). Not sure this is relevant.

In order to be able to move to the new Gradle version #31271 has a work around.
I'm writhing this up in the hopes of revisiting it to provide more clarity.
Note that as of this writing the Gradle 4.8 PR mentioned above is not merged.

Relates to #31230.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions