You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AbstractScheduledEventExecutor.schedule should have the runnable fire at the desired future time.
Actual behavior
The runnable.run() get executed immediately
Steps to reproduce
Simply schedule a runnable with a future time, for example:
new NioEventLoopGroup().schedule(() -> System.out.println("Execute"), 10, TimeUnit.SECONDS).get();
Then compile to a binary using native-image. Execute the native-image on a different machine, and there will be a non-zero chance that the runnable would get executed immediately.
I believe the main reason is due to the AbstractScheduledEventExecutor.START_TIME was initialized at compiled time, hence getting the nanoTime on the machine where the native image built happened. Later on when it gets executed on a different machine, in the defaultCurrentTimeNanos() method, it is comparing the System.nanoTime on the current machine to the one get determined at the compile time, hence it breaks, since System.nanoTime() cannot be compared across different VM.
Consider moving the START_TIME as an instance field instead of static. Alternatively, adding AbstractScheduledEventExecutor to the native-image.properties to initialize at run time.
Netty version
4.1.87.Final
JVM version (e.g. java -version)
Java version: openjdk version "17.0.2" 2022-01-18
Native image container: ghcr.io/graalvm/native-image:22.3.2
OS version (e.g. uname -a)
Native image OS: Linux 373c32b3fff1 5.15.107+ #1 SMP Sat May 6 09:12:19 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
The text was updated successfully, but these errors were encountered:
Consider moving the START_TIME as an instance field instead of static
I think will work although I'm not super happy about performing specific changes that make things to work for a single type of JDK (runtime behaviour, maybe but still sad, but not introducing fields), but maybe @normanmaurer or @chrisvest are fine with that.
A different approach (which performance effects are still to be evaluated and could be worse then your proposal!!) could be:
eg
I didn't proposed any lazy "static" pattern, because I have no idea if native image works fine with that, but it could be a different way to solve this, if works.
Expected behavior
AbstractScheduledEventExecutor.schedule should have the runnable fire at the desired future time.
Actual behavior
The runnable.run() get executed immediately
Steps to reproduce
Simply schedule a runnable with a future time, for example:
Then compile to a binary using native-image. Execute the native-image on a different machine, and there will be a non-zero chance that the runnable would get executed immediately.
I believe the main reason is due to the
AbstractScheduledEventExecutor.START_TIME
was initialized at compiled time, hence getting the nanoTime on the machine where the native image built happened. Later on when it gets executed on a different machine, in thedefaultCurrentTimeNanos()
method, it is comparing theSystem.nanoTime
on the current machine to the one get determined at the compile time, hence it breaks, sinceSystem.nanoTime()
cannot be compared across different VM.Current workaround
Add
to the native-image command
Proposed fix
Consider moving the START_TIME as an instance field instead of static. Alternatively, adding AbstractScheduledEventExecutor to the native-image.properties to initialize at run time.
Netty version
4.1.87.Final
JVM version (e.g.
java -version
)Java version: openjdk version "17.0.2" 2022-01-18
Native image container: ghcr.io/graalvm/native-image:22.3.2
OS version (e.g.
uname -a
)Native image OS: Linux 373c32b3fff1 5.15.107+ #1 SMP Sat May 6 09:12:19 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
The text was updated successfully, but these errors were encountered: