[GR-34103] Shutdown hooks not called when -H:-ParseRuntimeOptions is set
Hello!
It appears that -H:+UnlockExperimentalVMOptions -H:-ParseRuntimeOptions and --install-exit-handlers are not compatible with each other.
If -H:-ParseRuntimeOptions is set during build, the shutdown hooks won't run on sig TERM.
Tested with Graalvm CE 22.0.2
reproducer:
package repro.graalsignals;
import java.util.List;
public class Graalsignals {
// run with: 'target/graalsignals -Dpropkey=hello'
// then kill process (SIGTERM) and check if the shutdown task ran
public static void main(String[] args) throws InterruptedException {
System.out.println("-Dpropkey=" + System.getProperty("propkey"));
System.out.println("args: " + List.of(args));
Runtime.getRuntime().addShutdownHook(new Thread(() -> System.out.println("shutdown hook called")));
int n = 0;
while (true) {
Thread.sleep(1000);
System.out.println("sleeping "+n++);
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>repro</groupId>
<artifactId>graalsignals</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>21</maven.compiler.release>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.10.2</version>
<configuration>
<skip>false</skip>
<mainClass>repro.graalsignals.Graalsignals</mainClass>
<imageName>graalsignals</imageName>
<buildArgs>
--install-exit-handlers
-H:+UnlockExperimentalVMOptions
-H:-ParseRuntimeOptions
</buildArgs>
</configuration>
<executions>
<execution>
<goals>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
(i have nothing to do with the post above, I wouldn't recommend downloading random zips from the internet)
edit: spam got removed
Hi @mbien, Thank you for reaching out to us. We're currently taking a look into this. I will get back to you regarding this shortly
When the -H:-ParseRuntimeOptions flag is specified, VMRuntime.initialize() isn't executed, which prevents startup hooks from working. These hooks are necessary for implementing the --install-exit-handlers flag.
Our team is looking into this issue. I'll keep you posted with any new findings.