question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to override config properties for Isolates running in native mode

See original GitHub issue

Describe the bug The code, that relies on Isolates running in Native image is unable to catch overridden config properties (either passed as command line arguments when launching native executable or overriding properties with QuarkusTestResourceLifecycleManager in Native tests). It seems Isolates use the values of properties that are effective at image build time and do not override them in runtime.

Expected behavior Isolates use the values of properties that are effective at runtime (as Native-image code without isolates does).

Actual behavior Isolates use the values of properties that are effective at build time and do not override at runtime.

To Reproduce

	public int readPropertyValue() {
		var params = CreateIsolateParameters.getDefault();
		var isolateThread = Isolates.createIsolate(params);

		try {
			return processInIsolate(isolateThread);
		}
		finally {
			Isolates.tearDownIsolate(isolateThread);
		}

	}

	@CEntryPoint
	private static int processInIsolate(@CEntryPoint.IsolateThreadContext IsolateThread isolateThread) {
		int propertyToOverride = ConfigProvider.getConfig().getValue("property.to.override", Integer.class);
		System.out.println("property.to.override: " + propertyToOverride);

		return propertyToOverride;
	}

Demo app, reproducing the bug

https://github.com/AndreiYu/isolates-native-image-testing-bug/blob/master/src/native-test/java/com/example/config/NativeTest.java

Steps to reproduce the behavior:

  1. run ./gradlew testNative for demo app

Configuration

# Add your application.properties here, if applicable.

quarkus:
  package:
    type: native
  native:
    native-image-xmx: 12g

property:
  to:
    override: 0

Screenshots (If applicable, add screenshots to help explain your problem.)

Environment (please complete the following information):

  • Output of uname -a or ver: Darwin MacBook-Pro.local 20.2.0 Darwin Kernel Version 20.2.0: Wed Dec 2 20:39:59 PST 2020; root:xnu-7195.60.75~1/RELEASE_X86_64 x86_64
  • Output of java -version:
  • GraalVM version (if different from Java): 20.2.0.r11-grl
  • Quarkus version or git rev: 1.10.5.Final
  • Build tool (ie. output of mvnw --version or gradlew --version): gradle 6.5.1

Additional context (Add any other context about the problem here.)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
zakkakcommented, Jan 19, 2022

@zakkak Do you have any opinion on this one? I don’t have any test app for that.

@Karm @AndreiYu this is a GraalVM issue, I opened https://github.com/oracle/graal/issues/4238 to track it.

1reaction
AndreiYucommented, Jan 20, 2022

We made a workaround - CustomRuntimeConfigSource that has higher ordinal than System properties and Environment Variables

https://quarkus.io/guides/config-extending-support#example

Isolates are unable to see changes of system properties (since they have a snapshot of Image Heap at build or start time of native executable), but isolate refreshes env_variable changes with CustomRuntimeConfigSource with ordinal 500 and evaluates them at change. Here is a snippet of code:

@StaticInitSafe public class RuntimeEnvConfigSource implements ConfigSource {

@Override
public Map<String, String> getProperties() {
	return System.getenv();
}

@Override
public Set<String> getPropertyNames() {
	return System.getenv().keySet();
}

@Override
public int getOrdinal() {
	return 500;
}

@Override
public String getValue(String name) {
	if (name == null) {
		return null;
	}

	// exact match
	var data = System.getenv();
	String value = data.get(name);
	if (value != null) {
		return value;
	}

	// replace non-alphanumeric characters by underscores
	String sanitizedName = replaceNonAlphanumericByUnderscores(name);
	value = data.get(sanitizedName);
	if (value != null) {
		return value;
	}

	// replace non-alphanumeric characters by underscores and convert to uppercase
	return data.get(sanitizedName.toUpperCase());
}

@Override
public String getName() {
	return RuntimeEnvConfigSource.class.getSimpleName();
}

}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Building a Native Executable - Quarkus
You can override the profile the executable runs with during the test using the quarkus.test.native-image-profile property.
Read more >
How to override application.properties during production in ...
Show activity on this post. I'm using spring boot and application. properties to select a database during development by @Configuration @Profile("dev") . ...
Read more >
Core Features - Spring
If your application fails to start, registered FailureAnalyzers get a chance ... You can also use the spring.main.banner-mode property to determine if the ......
Read more >
dotnet test command - .NET CLI | Microsoft Learn
Runs the tests in blame mode. This option is helpful in isolating problematic tests that cause the test host to crash.
Read more >
How to Use Kafka Connect - Getting Started
Distributed mode: Runs Connect workers on multiple machines (nodes), ... Use the plugin.path configuration property which properly isolates each plugin from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found