JDA
JDA copied to clipboard
JDA hangs with JDK17 on a single core x64 Linux machine
Bug Report
When using JDA 4.3.0_331 with JDK17 on a single core Linux machine, JDA is unable to login to Discord.
Expected Behavior
Should be able to login to Discord and not hang.
Code Example or Reproduction Steps
To reproduce, follow these steps on an x64 Linux machine (I reproduced on Ubuntu 18.04 and 20.04):
- Clone this bot
- Download and extract JDK17
- Build the bot with
mvn package - Configure a Discord token with
export DISCORD_TOKEN=<TOKEN_HERE> - Run the jar with Java 17 and a single core:
taskset --cpu-list 1 java -jar target/modus-rollens-1.0-SNAPSHOT.jar
Workaround
You can bypass this issue by explicitly setting the fork join pool parallelism on startup:
taskset --cpu-list 1 java -Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -jar target/modus-rollens-1.0-SNAPSHOT.jar
https://bugs.openjdk.java.net/browse/JDK-8274349?focusedCommentId=14450437&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-14450437
https://github.com/openjdk/jdk/pull/5784
Got noticed by another bot developer too, not JDA's fault
This can be bypassed by use of the following code Note, this code should run before everything else
final int cores = Runtime.getRuntime().availableProcessors();
if (cores <= 1) {
System.out.println("Available Cores \"" + cores + "\", setting Parallelism Flag");
System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "1");
}
Otherwise you'll have to wait, this will be fixed in the next OpenJDK release.
The issue is resolved in Java 17.0.2 which was released on January 18th.
Closing this, since the JDK bug has been fixed 2 years ago.