Alfred456654
Alfred456654

Reputation: 195

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:


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.

Upvotes: 8

Views: 2152

Answers (3)

eis
eis

Reputation: 53543

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".

Upvotes: 2

lhf void
lhf void

Reputation: 11

Does it help if you add the following in Help | Edit Custom Properties and restart the IDE?

debugger.attach.to.process.action=false
execution.dump.threads.using.attach=false

From: Intellij keeps dumping threads when running simplest application with openjdk 11

Upvotes: 1

Alfred456654
Alfred456654

Reputation: 195

I also posted my question on Reddit and someone suggested that such full thread dumps are displayed when the process receives a signal 3.

I was unable to detect that signal being sent to it by using strace, but I did notice that running the code in command line rather than inside my IDE solved the issue.

I also tried sending a signal 3 to the program running in command line, and it does display the same full thread dump.

Kind of unsatisfactory ending, I'm not 100% sure what's happening, but I'm getting confident that this is a non-issue that I can ignore.

Upvotes: 3

Related Questions