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

NativeClosureProxy - Callable is null #180

Open
PhBastiani opened this issue Nov 18, 2022 · 3 comments
Open

NativeClosureProxy - Callable is null #180

PhBastiani opened this issue Nov 18, 2022 · 3 comments

Comments

@PhBastiani
Copy link

PhBastiani commented Nov 18, 2022

Hi,

What is wrong with this code ?

    POSIX posix = POSIXFactory.getPOSIX();
    posix.signal(Signal.SIGUSR1, new SignalHandler() {
      @Override
      public void handle(int i) {
        System.out.println("handle: " + i);
        }
    });

kill -s USR1 <PID> gives me a nullPointerException during the call of NativeClosureProxy.getCallable()

Tested on : Operating System: Red Hat Enterprise Linux Server 7.4 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.4:GA:server
Kernel: Linux 3.10.0-693.el7.x86_64
Architecture: x86-64

jnr.posix 3.0.29 (and 3.1.15')

Note : same exception with LibC part of jnr

@PhBastiani
Copy link
Author

Any comments on this issue would be appreciated.

Is there another alternative to hijack a system signal ?

Best wishes,
Philippe

@headius
Copy link
Member

headius commented Jan 4, 2023

Sorry for the delay in responding!

Can you turn this into a runnable test or simple compilable project? That would help me investigate.

However... I suspect this is the JVM getting in your way. Most builds of OpenJDK include some logic that uses the USR1 and other signals for JVM features. In order to avoid those signals being trapped by user code (primarily from C) the logic to bind signals is hooked so that it passes through JDK logic first that can protect these signals.

You may be able to get this work by telling the JVM to reduce the signals it traps using the -XX:+UseAltSigs flag:

$ java -XX:+PrintFlagsFinal -version | grep UseAltSigs
     bool UseAltSigs                                = false                               {product}
openjdk version "1.8.0_352"
OpenJDK Runtime Environment (build 1.8.0_352-b08)
OpenJDK 64-Bit Server VM (build 25.352-b08, mixed mode)

See this article for more information: https://www.oracle.com/java/technologies/javase/signals.html#gbzcj

Some newer versions of Java may not block USR1 in this way, but I'm not sure which platforms or versions.

@PhBastiani
Copy link
Author

PhBastiani commented Jan 23, 2023

Sorry, I couldn't investigate further...

$java -XX:+PrintFlagsFinal -version | grep UseAltSigs

java version "11.0.9" 2020-10-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.9+7-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.9+7-LTS, mixed mode)

So, no UseAltSigs on this JVM !
But, I've the following flags
bool AllowUserSignalHandlers = false {product} {default}
bool ReduceSignalUsage = false {product} {default}
bool UseSignalChaining = true {product} {default}

From my goldfish memory, I also tested with other signals (since in my outdated code I was using sun.misc.Signal.HUP...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants