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

[GR-34103] Shutdown hooks not called when -H:-ParseRuntimeOptions is set #9568

Open
mbien opened this issue Aug 26, 2024 · 3 comments
Open
Assignees

Comments

@mbien
Copy link

mbien commented Aug 26, 2024

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>
@mbien

This comment was marked as outdated.

@selhagani selhagani self-assigned this Aug 26, 2024
@selhagani
Copy link
Member

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

@selhagani
Copy link
Member

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.

@selhagani selhagani changed the title Shutdown hooks not called when -H:-ParseRuntimeOptions is set [GR-34103] Shutdown hooks not called when -H:-ParseRuntimeOptions is set Aug 27, 2024
@wirthi wirthi assigned peter-hofer and unassigned christianwimmer Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
@mbien @christianwimmer @peter-hofer @selhagani and others