Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
Bug 135475 - maven processes keep alive after stopping them
maven processes keep alive after stopping them
Status: RESOLVED FIXED
Product: projects
Classification: Unclassified
Component: Maven
6.x
PC Windows XP
: P3 with 7 votes (vote)
: 6.x
Assigned To: Milos Kleint
issues@platform
:
: 145256 149445 160270 162878 166654 167337 169287 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-05-21 08:41 UTC by bartvdc
Modified: 2016-07-11 07:25 UTC (History)
6 users (show)

See Also:
Issue Type: DEFECT
:


Attachments
experimental module capable of killing maven builds entirely (165.32 KB, application/octet-stream)
2009-06-19 14:04 UTC, Milos Kleint
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bartvdc 2008-05-21 08:41:24 UTC
When a maven process is started(test project,...), you can stop it from within the NB(unlike in 6.0). NB shows that the
process is stopped but it's still running in the background.
Comment 1 Milos Kleint 2008-05-21 09:32:02 UTC
->maven
Comment 2 Milos Kleint 2008-05-21 09:33:17 UTC
most probably a duplicate of http://jira.codehaus.org/browse/MEVENIDE-566
Comment 3 Milos Kleint 2008-11-25 07:58:21 UTC
a jdk issue, still looking for workaround if any..

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4770092
Comment 4 Milos Kleint 2008-11-28 15:17:16 UTC
*** Issue 149445 has been marked as a duplicate of this issue. ***
Comment 5 Milos Kleint 2008-11-29 12:52:57 UTC
There seems to be a library for killing windows processes.

https://winp.dev.java.net/
http://maven.dyndns.org/2/org/jvnet/winp/winp/1.5/

hudson.util.ProcessTreeKiller class in hudson makes use of it and it also provides ways of killing unix/solaris processes.
Comment 6 Milos Kleint 2009-03-19 10:06:13 UTC
*** Issue 160270 has been marked as a duplicate of this issue. ***
Comment 7 Milos Kleint 2009-03-25 21:41:21 UTC
the root cause of the problem seems to be in plexus-utils component in maven
see http://jira.codehaus.org/browse/PLXUTILS-40

I've tried to write a -javaagent for the maven build that patches the org.codehaus.classworlds.Launcher class (main
class of the build JVM) to spawn a Thread that just listens on a port and when the connection is established, kills
itself (the build JVM) with System.exit().
That seems to exhibit the same behaviour as sending signals to the build jvm. The build jvm is shutdown, the shutdown
hooks are run, but the forked test JVM keeps running. I suspect it's caused by the (IMHO dubious) execution of "sh -c cd
<workdir>&& java -cp <cp> <mainclass>". that plexus-utils' CommandLineUtils wrap each execution request into.
Comment 8 Milos Kleint 2009-04-10 14:53:32 UTC
*** Issue 145256 has been marked as a duplicate of this issue. ***
Comment 9 Milos Kleint 2009-04-17 09:51:12 UTC
*** Issue 162878 has been marked as a duplicate of this issue. ***
Comment 10 uprooter 2009-05-14 16:47:28 UTC
This is high priority, as it leads to resource starvation and more important blows your head off when you try to debug
client/server applications 
Comment 11 uprooter 2009-05-14 17:46:54 UTC
A quick n dirty workaround I just made until this issue is solved.
A custom maven goal and a tiny unix shell script to kill the instance.

1.put this in nbaction.xml, rename NewClass to your runnable class name.
---------
       <action>
            <actionName>CUSTOM-kill</actionName>
            <displayName>kill</displayName>
            <goals>
                <goal>process-classes</goal>
                <goal>org.codehaus.mojo:exec-maven-plugin:1.1:exec</goal>
            </goals>
            <properties>
                <exec.args>./jpkill NewClass</exec.args>
                <exec.executable>exec</exec.executable>
                <forkMode>once</forkMode>
            </properties>
        </action>
-----------
2.put this shell script in your project , make sure it's executable
--------------------------

#!/bin/sh
echo -n "Kill $1 $2... "
NAME=`/usr/bin/jps -l | grep -i $1`
if [ "$NAME" = "" ]; then
  echo "Proccess $1 not found"
  exit
fi
echo -n "$NAME..."
PID=`echo $NAME | awk {'print $1'}`
if [ "$PID" = "" ]; then
  echo "Pid not found"
  exit
fi
if [ $PID -lt 100 ]; then
    echo "$PID < 100. abort kill"
    exit
fi
kill $2 $PID &&
echo "..Done"
---------------

now instead of stopping with in the regular way, right click on your project->custom->kill
No guarantee etc..
Hope that helps.
Comment 12 Milos Kleint 2009-06-08 07:32:02 UTC
uprooter: P4 has less priority than P3, you've actually decreased the priority of this issue.
Comment 13 Milos Kleint 2009-06-08 07:32:21 UTC
*** Issue 166654 has been marked as a duplicate of this issue. ***
Comment 14 Masaki Katakai 2009-06-10 04:48:28 UTC
Milos,

Any quick workaround for 6.7?
Comment 15 igorminar 2009-06-13 11:04:47 UTC
come on guys, please get this one fixed before 6.7 final otherwise all the great work done for maven integration will be
overshadowed by this unfortunate issue.

I noticed that when I run my maven project with debugger attached, the stop functionality works properly. I haven't
looked into this further, but maybe that indicates that there is a way to get it working properly even without the debugger.
Comment 16 Milos Kleint 2009-06-13 11:20:08 UTC
Sorry, the deadline for 6.7 is long passed.

Right now I'm experimenting with calling maven build without the shell script/bat file, but directly. That should help
with builds alone, but spawned processes (forked surefire and exec-maven-plugin) still don't work.

other options include some platform specific means of killing.
Comment 17 rbuss 2009-06-13 14:11:14 UTC
I think Igor Minar is right. This problem foils the good maven integration in netbeans. As a workaround I use, as Igor, the debugger for running applications. 
But this costs time. In my opinion this issue should be fixed in a bugfix release.
Comment 18 Masaki Katakai 2009-06-14 14:31:55 UTC
Can we convert Maven project to usual NetBeans Java project?
Comment 19 Milos Kleint 2009-06-19 14:04:43 UTC
Created attachment 83808 [details]
experimental module capable of killing maven builds entirely
Comment 20 Milos Kleint 2009-06-19 14:13:50 UTC
the attached experimental module is capable of kill the process trees on all supported platforms (I've tested on windows
and linux), it will start working in development builds after a few relevant changed are added to base modules. the
upcoming automated message will point out which build is the first one to support it.

The work is based on Hudson's codebase that is killing the processes via the jna, winp and libpam4j libraries. It's
searching all relevant processes for a magic environment variable that was passed to the root process and that was
inherited by any spawned child process and it kills all such processes found.

We will need some more testing before this ends up in standard build  (please test on your setup if you can)

And also we will need to go through license approval:
7D1238825F32E60EA09CE97071239434F3D68639 winp-1.10.jar - MIT license - https://winp.dev.java.net/ 
2E07375E5CA3A452472F0E87FB33F243F7A5C08C libpam4j-1.1.jar - MIT license - https://libpam4j.dev.java.net/
EA85C7BB7773A46AABFDF60672EB335F8B5A5459 processtreekiller-1.0.jar - MIT license -
http://kenai.com/projects/nb-process-killler
A8762D07E76CFDE2395257A5DA47BA7C1DBD3DCE commons-io-1.4.jar - Apache License - http://commons.apache.org/io/

We should also consider to make the codebase part of some api (external execution probably the best place).
Comment 21 Petr Hejl 2009-06-19 15:06:20 UTC
I agree. Once this is tested we should make it API. There is issue 138116. We should either close it as duplicate or use
it for API tracking.

This is important enhancement as there are many commands NetBeans is using these days, such as maven, grails, php...
Comment 22 Quality Engineering 2009-06-20 08:07:41 UTC
Integrated into 'main-golden', will be available in build *200906200201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/f1c8347a993c
User: Milos Kleint <mkleint@netbeans.org>
Log: #135475 create new module that's capable of killing process trees, derived from hudson.core, using native libraries. Recognizes the child processes by inherited special environment variable that identifies the spawned child processes
Comment 23 Milos Kleint 2009-06-23 14:14:54 UTC
*** Issue 167337 has been marked as a duplicate of this issue. ***
Comment 24 uprooter 2009-06-29 18:02:04 UTC
mkleint. can you please do something that it will be possible to install the module killer on 6.7 ?
it complains about dependency modules too old.
Comment 25 Milos Kleint 2009-06-30 06:31:17 UTC
uprooter: sorry, this won't work, there is code missing in the 6.7 version of maven modules that would call this new
module's killing method.
Comment 26 Milos Kleint 2009-07-01 13:43:03 UTC
these changesets push the experimental module into standard build (a bit reworked), since now the experimental module is
not working anymore but it should work automatically.

http://hg.netbeans.org/main/rev/7274fb0c27c2
http://hg.netbeans.org/main/rev/ef9832e4cb2c
http://hg.netbeans.org/main/rev/7d5e585ed012

I consider the issue fixed for 6.8. Please verify in the first build containing the changes.
Comment 27 Quality Engineering 2009-07-03 05:59:01 UTC
Integrated into 'main-golden', will be available in build *200907030200* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/7d5e585ed012
User: Milos Kleint <mkleint@netbeans.org>
Log: #138116, #135475 proper termination of external maven processes via extexecution api call.
Comment 28 Milos Kleint 2009-07-28 09:51:31 UTC
*** Issue 169287 has been marked as a duplicate of this issue. ***
Comment 29 chakie 2013-11-14 16:32:10 UTC
I still see this with 7.3 and 7.4. Running projects and then stopping them leaves the Java process in the background. NB thinks it's killed. When doing client/server based stuff this means I have to go kill my processes externally between every single run, and it gets a bit boring quite fast.

I won't reopen this though, not my task to do that, could be that this bug is just a duplicate and the real work is done somewhere else.
Comment 30 ccomer 2013-11-26 08:33:50 UTC
This is definitely still occurring with Netbeans 7.4. 

Steps to reproduce:

1. Create a new Maven web application project. (File > New Project, Categories: Maven, Projects: Web Application)
2. Create a simple class to run, something like:

class MyClass {
    public static void main(String[] args) throws InterruptedException {
        while (true) { Thread.sleep(1000); }
    }
}

3. Run the file (Right click the file, select 'Run File' or press Shift+F6)
4. Inspect your running processes, you should see two java processes. 
5. Stop the Maven build (Click the red square on the left hand side of the output window)
5. Inspect your running processes, you should see one java process running still. 

This is extremely annoying when you're working on something that needs to listen on a particular port or happens to use a lot of resources as subsequent runs will cause multiple instances of the application to run in the background. 

The work around I have found for this is to never simply 'run' the application, but always launch it via a debugging session. The stop button on the output window still does not work as expected but the "Finish Debugging Session" button in the toolbar or Shift+F5 will terminate both running java processes. 

Like the comment above, I'm not sure about the workflow for reopening something like this, so I'll defer to someone more experienced to make that call.
Comment 31 ccomer 2013-11-26 08:38:26 UTC
(In reply to ccomer from comment #30)
> This is definitely still occurring with Netbeans 7.4. 
> 
> Steps to reproduce:
> 
> 1. Create a new Maven web application project. (File > New Project,
> Categories: Maven, Projects: Web Application)
> 2. Create a simple class to run, something like:
> 
> class MyClass {
>     public static void main(String[] args) throws InterruptedException {
>         while (true) { Thread.sleep(1000); }
>     }
> }
> 
> 3. Run the file (Right click the file, select 'Run File' or press Shift+F6)
> 4. Inspect your running processes, you should see two java processes. 
> 5. Stop the Maven build (Click the red square on the left hand side of the
> output window)
> 5. Inspect your running processes, you should see one java process running
> still. 
> 
> This is extremely annoying when you're working on something that needs to
> listen on a particular port or happens to use a lot of resources as
> subsequent runs will cause multiple instances of the application to run in
> the background. 
> 
> The work around I have found for this is to never simply 'run' the
> application, but always launch it via a debugging session. The stop button
> on the output window still does not work as expected but the "Finish
> Debugging Session" button in the toolbar or Shift+F5 will terminate both
> running java processes. 
> 
> Like the comment above, I'm not sure about the workflow for reopening
> something like this, so I'll defer to someone more experienced to make that
> call.

Quick clarification, when checking the running processes, be aware there may be several additional java processes depending on what you have running, and at least two for Netbeans. Make sure you account for that when checking what is running using ps, Activity Monitor, Process Monitor or your tool of choice. I used ps aux | grep '<project name>' and Activity Monitor on OSX 10.9
Comment 32 Milos Kleint 2013-11-26 08:44:33 UTC
we can only reliably kill the maven JVM itself. Any other JVMs that maven spawns are outside of our capacity to kill as far as I can see. Definitely not supported by the JDK. AFAIK jenkins employs quite some tricks (including platform specific code/shell scripts) to get rid of such spawned grandchildren processes.
Comment 33 StephaneJ 2016-07-05 10:25:28 UTC
This bug still occur in netbeans 8.1

I have same pb when i use exec-maven-plugin and run it with netbeans.

If i run maven command from terminal and press ctrl+c, all process are killed.  Netbeans kill the process differently?
Comment 34 StephaneJ 2016-07-05 10:28:05 UTC
Spring boot has same problem

see last comment of "wilkinsona" here : https://github.com/spring-projects/spring-boot/issues/4457
Comment 35 Petr Hejl 2016-07-11 07:25:23 UTC
Should be fixed in dev version.


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo