Search code examples
javalinuxintellij-ideadump

Java outputs a Full Thread Dump every few seconds when running from IntelliJ and given network sniffing permissions with setcap


I am writing an application that does packet sniffing using a Pcap library. For that to work, I need to give the java binary network sniffing capabilities to avoid having to run it as root:

sudo setcap cap_net_raw,cap_net_admin=eip /path/to/bin/java

When I run any program, every few seconds, I get a Full Thread Dump to stdout. Here is an example of such a full thread dump (the rest of the repo is irrelevant). The program otherwise seems to run successfully: except for the dump, I couldn't find a difference in the execution.

The code below is sufficient to reproduce the issue:

package main;

import java.io.IOException;

public class StdinTest {
    public static void main(String[] args) throws IOException {
        System.in.read();
    }
}

When I remove the capabilities from the java binary with the command below, things go back to normal and I no longer get the Full Thread Dumps to stdout.

sudo setcap -r /path/to/bin/java

I'm not sure it's a problem since the program seems to run fine, but it doesn't look normal.

I haven't found anyone who seems to have a similar issue, I'm a bit lost...

Any help is appreciated, thanks in advance!


Details:

  • OS: reproduced on ArchLinux (kernel 5.12.9) & Ubuntu 20.04 (kernel 5.8.0)
  • JDK: reproduced on Adopt OpenJDK 11, 15 & 16, openjdk.java.net 15 & 16.

EDIT:

Not reproduceable if the program is ran in command line:

java -classpath target/classes main.StdinTest

I only get the symptoms when starting it from IntelliJ Idea Ultimate. I haven't tried with other IDEs.


Solution

  • If intelliJ thinks your software is stuck, it will take thread dumps from it. System.in.read(); makes it "stuck" on reading from stdin.

    You should be able to disable it using -Dperformance.watcher.unresponsive.interval.ms=0 in VM options. The recommended way of changing the JVM options is via the Help | Edit Custom VM Options action.

    Reference: intellij support: Disable "Automatic thread dumps".