JDA icon indicating copy to clipboard operation
JDA copied to clipboard

JDA hangs with JDK17 on a single core x64 Linux machine

Open mbarkley opened this issue 4 years ago • 3 comments

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):

  1. Clone this bot
  2. Download and extract JDK17
  3. Build the bot with mvn package
  4. Configure a Discord token with export DISCORD_TOKEN=<TOKEN_HERE>
  5. 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

mbarkley avatar Oct 05 '21 03:10 mbarkley

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

Tais993 avatar Oct 05 '21 05:10 Tais993

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.

Tais993 avatar Oct 13 '21 08:10 Tais993

The issue is resolved in Java 17.0.2 which was released on January 18th.

SirYwell avatar Jan 26 '22 13:01 SirYwell

Closing this, since the JDK bug has been fixed 2 years ago.

MinnDevelopment avatar Jan 21 '24 09:01 MinnDevelopment