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

3

8

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.

Senatorial answered 7/6, 2021 at 7:57 Comment(2)
IDEA prints the exact command line it uses to start Java processes at the beginning of the output. Did you check if any of the arguments it uses can help you reproduce the issue? For example I'm pretty sure they add an agent of theirs to the JVM.Braithwaite
Weirdly enough, it adds plenty of python to the classpath... I pasted it here: gist.github.com/giraudan/466cf36c1605174e0bb5b99be7bb2922Senatorial
H
2

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

Hornet answered 8/6, 2021 at 9:34 Comment(1)
I added that option to my IDE's VM options, restarted it just in case, but it didn't change the problem. To be extra-sure, I also added it in my idea.properties file. Thank you for your suggestion though!Senatorial
S
3

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.

Senatorial answered 8/6, 2021 at 9:23 Comment(0)
H
2

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

Hornet answered 8/6, 2021 at 9:34 Comment(1)
I added that option to my IDE's VM options, restarted it just in case, but it didn't change the problem. To be extra-sure, I also added it in my idea.properties file. Thank you for your suggestion though!Senatorial
W
1

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

Whereinto answered 13/1, 2022 at 16:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.