13

I'm using idea 2016.1.1 and wonder why idea does not kill the debug process immediately when I click the stop button.

E.g. use this piece of code to reproduce it

public class Main {

  public static void main(String[] args) {
    int i = 0;
    while (true) {
      i++;
      System.out.print("I'm still alive: ");
      System.out.println(i);
    }
  }
}

Set a breakpoint before the loop begins.

enter image description here

Start a debugging session, wait until it breaks and press the red stop button (CTRL-F2).

enter image description here

I would expect that the process is stopped immediately and that it does not print anything, but it prints:

"C:\Program Files\Java\jdk1.6.0_38\bin\java" ....
Connected to the target VM, address: '127.0.0.1:54394', transport: 'socket'
Disconnected from the target VM, address: '127.0.0.1:54394', transport: 'socket'
I'm still alive: 1
I'm still alive: 2
I'm still alive: 3
I'm still alive: 4
...
I'm still alive: 319
I'm still alive: 320
I'm still alive: 321
I'm still alive: 
Process finished with exit code -1

Why is the process not stopped immediately?

Is there another way to force an immediately stop?

EDIT

Just tried it with idea 14.1.5. The process stops immediately as expected. It seems that a bug was introduced with 2016.

Ahmed Nabil
  • 17,392
  • 11
  • 61
  • 88
René Link
  • 48,224
  • 13
  • 108
  • 140

3 Answers3

9

When press Stop during a debugging session,
The default behavior of IntelliJ Idea is not to kill the process immediately!.

But if you need to change this behavior to kill the debugging process immediately
Which I think that, should be the default behavior :)

You can activate it via the Settings:
Settings > Build, Execution, Development > Debugger >

enter image description here

Ahmed Nabil
  • 17,392
  • 11
  • 61
  • 88
  • This has started happening to me on version 2020.3 on Mac OS 10.15.7. This setting has no affect. – Sean Anderson Aug 17 '21 at 18:16
  • 1
    This should be the accepted answer. This functionality is working as of 2020.3. Agreed the default behavior should be flipped since not immediately killing the process seems unintuitive and can lead to all sorts of nasty side effects. – Brett Hannah Nov 18 '21 at 15:56
  • 1
    IMHO this shouldn't be a config; we should have 2 distinct buttons, such as Stop the Debug session (which should kill the process immediately) and Detach from Debugger (which would continue the process). So the choice can be made at debug time. – Ricardo Sep 20 '22 at 18:42
4

My investigations so far...

When IDEA starts a java process it uses main wrapper. This wrapper starts a daemon thread that listens to a ServerSocket for commands.

IDEA sends a STOP signal to that server socket. When the server thread receives the STOP signal it exists the jvm using System.exit(1).

It seems that IDEA resumes the JVM from debug and then sends the STOP signal. So until the STOP signal is received the process continues.

I opened a bug at https://youtrack.jetbrains.com/issue/IDEA-155007

René Link
  • 48,224
  • 13
  • 108
  • 140
4

The bug IDEA-155007 is fixed in 2016.3 (163.7743.44). I've just verified it.

René Link
  • 48,224
  • 13
  • 108
  • 140
  • still happening for me with the latest. Edit: nevermind, there's a setting mentioned here: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000112384-Intellij-IDEA-doesn-t-stop-test – b15 May 23 '19 at 15:04