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

Virtual threads and native image fails on NoSuchElementException #7818

Closed
jkamon opened this issue Nov 14, 2023 · 9 comments
Closed

Virtual threads and native image fails on NoSuchElementException #7818

jkamon opened this issue Nov 14, 2023 · 9 comments
Assignees

Comments

@jkamon
Copy link

jkamon commented Nov 14, 2023

Describe the issue
Running multithreaded program build to native image using virtual threads and AccessController causes java.util.NoSuchElementException: null

Problem occurs only with virtual threads. 2 virtual threads are enough to cause the problem. Platform threads works as expected see attached replicator.zip.

We found this issue trying to run spring boot application as native build with virtual threads. Our application was using Apache HTTP5 client to create SSL connections. It uses SSLConnectionSocketFactory which works with socket inside AccessController (which is modified during native build).

Steps to reproduce the issue
Build:

  1. download attached replicator.zip
  2. unzip
  3. make clean install
  4. target folder contains replicator executable binary and jar file.

Run:

  1. simple execution of executor binary (./replicator) from target directory will cause exception see output below
  2. execution with java (java -jar replicator-1.0-SNAPSHOT.jar) will not cause exception

Describe GraalVM and your environment:
Environment used for replication of the issue:
java -version
openjdk version "21" 2023-09-19
OpenJDK Runtime Environment GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15)
OpenJDK 64-Bit Server VM GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15, mixed mode, sharing)

mvn -v
Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
Maven home: /home/USER/apache-maven-3.8.7
Java version: 21, vendor: GraalVM Community, runtime: /aplikace/USER/graalvm-community-openjdk-21+35.1
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.14.0-284.30.1.el9_2.x86_64", arch: "amd64", family: "unix"

uname -a
Linux HOST 5.14.0-284.30.1.el9_2.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Aug 25 09:13:12 EDT 2023 x86_64 x86_64 x86_64 GNU/Linux

More details
Thread name: virtual-0 - 2
Thread name: virtual-0 - 2
Thread name: virtual-0 - 2
Thread name: virtual-0 - 2
Thread name: virtual-0 - 2
Thread name: virtual-0 - 2
Thread name: virtual-0 - 2
Thread name: virtual-0 - 2
Thread name: virtual-0 - 2
Thread name: virtual-0 - 2
Thread name: virtual-1 - 2
Thread name: virtual-0 - 2
Exception in thread "virtual-1" java.util.NoSuchElementException
at java.base@21/java.util.ArrayDeque.removeFirst(ArrayDeque.java:361)
at java.base@21/java.util.ArrayDeque.pop(ArrayDeque.java:592)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.PrivilegedStack.pop(AccessControllerUtil.java:88)
at java.base@21/java.security.AccessController.executePrivileged(AccessController.java:116)
at java.base@21/java.security.AccessController.doPrivileged(AccessController.java:571)
at org.example.Main.lambda$main$1(Main.java:23)
at java.base@21/java.lang.VirtualThread.runWith(VirtualThread.java:341)
at java.base@21/java.lang.VirtualThread.run(VirtualThread.java:311)
at java.base@21/java.lang.VirtualThread$VThreadContinuation$1.run(VirtualThread.java:192)
Exception in thread "virtual-0" java.util.NoSuchElementException
at java.base@21/java.util.ArrayDeque.removeFirst(ArrayDeque.java:361)
at java.base@21/java.util.ArrayDeque.pop(ArrayDeque.java:592)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.PrivilegedStack.pop(AccessControllerUtil.java:88)
at java.base@21/java.security.AccessController.executePrivileged(AccessController.java:116)
at java.base@21/java.security.AccessController.doPrivileged(AccessController.java:571)
at org.example.Main.lambda$main$1(Main.java:23)
at java.base@21/java.lang.VirtualThread.runWith(VirtualThread.java:341)
at java.base@21/java.lang.VirtualThread.run(VirtualThread.java:311)
at java.base@21/java.lang.VirtualThread$VThreadContinuation$1.run(VirtualThread.java:192)

@hamzaGhaissi
Copy link
Member

Thank you for reporting, issue reproduced and we are looking into it

@jkamon jkamon changed the title Virtual threads and nativem image fails on NoSuchElementException Virtual threads and native image fails on NoSuchElementException Nov 15, 2023
@hamzaGhaissi
Copy link
Member

Issue is fixed see #7923 and will be back-ported to 23.1 thanks to @peter-hofer

@kunniks
Copy link

kunniks commented Dec 15, 2023

Can you please tell me which version of GraalVM this fix is available in?
I am using this version and the error is still reproduced:

# java -version
java version "21.0.1" 2023-10-17
Java(TM) SE Runtime Environment Oracle GraalVM 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19, mixed mode, sharing)
Unknown error [class java.io.IOException]: null
java.util.NoSuchElementException: null
	at java.base@21.0.1/java.util.ArrayDeque.removeFirst(ArrayDeque.java:361)
	at java.base@21.0.1/java.util.ArrayDeque.pop(ArrayDeque.java:592)
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.PrivilegedStack.pop(AccessControllerUtil.java:88)
	at java.base@21.0.1/java.security.AccessController.executePrivileged(AccessController.java:131)
	at java.base@21.0.1/java.security.AccessController.doPrivileged(AccessController.java:319)
	at java.net.http@21.0.1/jdk.internal.net.http.HttpRequestImpl.getAddress(HttpRequestImpl.java:386)

My app is: Kotlin 1.9.21, Java 21, Spring Boot 3.2 with Virtual Threads, Telegram Client.

@pompiuses
Copy link

pompiuses commented Dec 19, 2023

I'm getting the exact same error as well. Seemingly randomly when running Oracle GraalVM 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19). When will the fix be out?

@wpf375516041
Copy link

wpf375516041 commented Dec 26, 2023

I apologize for the disturbance, but I believe this issue is critically important for business development. Would it be possible to release a fixed version based on GraalVM CE 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19)? I sincerely appreciate your assistance. Thank you very much. @hamzaGhaissi

@hamzaGhaissi
Copy link
Member

hamzaGhaissi commented Dec 26, 2023

Issue already fixed, and will be released on the next EE/CE release of 23.1.2 on January

@kunniks
Copy link

kunniks commented Jan 3, 2024

Thank you for information.
According to the release calendar https://www.graalvm.org/release-calendar/ the next release can be expected on January 23rd

@hamzaGhaissi
Copy link
Member

Actually the date for the CE release was update it and will be on the 16th of January ^_^

@kunniks
Copy link

kunniks commented Jan 17, 2024

Today I built my application with the latest version of GraalVM - no error. Thanks!

# java -version
java version "21.0.2" 2024-01-16 LTS
Java(TM) SE Runtime Environment Oracle GraalVM 21.0.2+13.1 (build 21.0.2+13-LTS-jvmci-23.1-b30)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.2+13.1 (build 21.0.2+13-LTS-jvmci-23.1-b30, mixed mode, sharing)

My app is: Kotlin 1.9.22, Java 21, Spring Boot 3.2.1 with Virtual Threads, Telegram Client 6.8.0

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

6 participants