Bug 36903 - ANT Java Task hangs or causes other processes to hang
Summary: ANT Java Task hangs or causes other processes to hang
Status: RESOLVED DUPLICATE of bug 34461
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.6.5
Hardware: PC Windows 2000
: P2 blocker (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on: 24918
Blocks:
  Show dependency tree
 
Reported: 2005-10-04 05:49 UTC by Nosa Omorogbe
Modified: 2008-08-22 04:42 UTC (History)
2 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nosa Omorogbe 2005-10-04 05:49:03 UTC
In attempting to upgrade our build process to ANT 1.6.5 from ANT 1.6.2, we have 
encountered various hangs in java or other forked processes during our build 
process.
It appears to be a serious regression in the ANT Java Task.

We observed this behavior with ANT 1.6.{3,4,5} -- this bug is present in all 
three latest versions.
Everything worked perfectly with ANT 1.6.2.

Seems Bug fix 24918 has caused this regression.
Compared the sources of ANT 1.6.2 and 1.6.5 for Java Task;
the only notable change was this fix for 24918.

By just commenting these lines out and recompiling this 1 file, the hanging 
problems go away, and everything works on ANT 1.6.5.

apache-ant-1.6.5\src\main\org\apache\tools\ant\taskdefs\Java.java

    /**
     * Set up properties on the redirector that we needed to store locally.
     */
    protected void setupRedirector() {
        redirector.setInput(input);
        redirector.setInputString(inputString);
        redirector.setOutput(output);
        redirector.setError(error);
        if (redirectorElement != null) {
            redirectorElement.configure(redirector);
        }
        // if (!spawn && input == null && inputString == null) {
        //    #24918: send standard input to the process by default.
        //    redirector.setInputStream(new KeepAliveInputStream(getProject
().getDefaultInputStream()));
        // }
    }
 
We need this fix before we can upgrade our ANT version to the latest release :-(

We observed that sometimes adding fork="yes" to Java Task works around the 
problem, but at other points removing fork="yes" works around the problem, so 
have not been able to establish a consistent pattern for how to work around 
this.
We also observed that having fork="yes" option when running a java task, can 
sometimes cause other unrelated processes later on to hang, even though the 
java process itself successfully terminates (or so it seemed).

We have fairly complicated build scripts that invoke numerous java and non-java 
processes;
I have not yet been able to isolate a simple reproducible case.
We also do our builds using Cruise Control 
(http://cruisecontrol.sourceforge.net) and first observed it there.
Though, it has nothing to do with Cruise Control, as I can reproduce the 
problems easily by invoking the same ANT targets directly from bash command 
line.
Comment 1 J.M. (Martijn) Kruithof 2005-10-04 20:44:46 UTC
Could it be that a process started by ant waits for standard input?
Does adding a redirector with an empty inputstring help?
Comment 2 Nosa Omorogbe 2005-10-06 16:01:34 UTC
(In reply to comment #1)
> Could it be that a process started by ant waits for standard input?
> Does adding a redirector with an empty inputstring help?

We use a fully automated build process, so am not aware of our processes 
waiting for standard input, but we use some third party tools which am not sure 
about.

Yes, adding inputstring="" to java task makes processes downstream stop 
hanging, but why should this impact other processes?
Removing fork="yes" from the java process has the same effect sometimes.
But these are just workarounds.

Narrowed down the hangs in our build process to two scenarios.
One involves third party application (tomcat), the other does not.
Am attaching a standalone test-case for the first scenario.
Will attach the second scenario later; have not been able to make a
reproducible standalone test-case for the other one yet.

Have put together a standalone test case that hangs on ANT 1.6.{3,4,5}, but 
works on ANT 1.6.2.

NOTE:

1. have observed that this test case hangs if ant is invoked via cygwin (bash) 
shell or a parent java process like Cruise Control
(http://cruisecontrol.sourceforge.net).
It works as is if run in DOS Shell.

2. test-case works in bash if you remove fork="yes" from the ListProperties 
java task

3. test-case works in bash if you add inputstring="" to the ListProperties java 
task

Strange that making these changes to java task will affect completely unrelated 
processes downstream.

4. test-case works as is in bash or Cruise Control on ANT 1.6.2

STEPS:

1. Compile this java file into classes folder

ListProperties.java
-------------------

public class ListProperties {

	public static void main(String[] ignore) {
		System.getProperties().list(System.out);
	}
}

2. Use this ANT file:

test.xml
--------

<project name="tests" default="test" basedir=".">
  <description>
    Tests build file
  </description>

  <property environment="system"/>

  <property name="classes" location="classes"/>

  <!-- classpath -->
  <path id="class.path">
    <pathelement location="${classes}"/>
  </path>

  <target name="setup">
    <java classname="ListProperties"
          classpathref="class.path"
          failonerror="true"
          fork="yes"
          dir="${basedir}"/>
  </target>

  <target name="test" depends="setup">

    <exec executable="${system.CATALINA_HOME}/bin/shutdown.bat">
    </exec>

    <parallel>

      <exec executable="${system.CATALINA_HOME}/bin/startup.bat">
      </exec>

      <sequential>
        <echo message="Waiting for http://localhost:8080/tomcat-
docs/index.html"/>

        <waitfor maxwait="3" maxwaitunit="minute" checkevery="3000"
                 timeoutproperty="web.page.not.available">
          <http url="http://localhost:8080/tomcat-docs/index.html"/>
        </waitfor>

        <exec executable="${system.CATALINA_HOME}/bin/shutdown.bat">
        </exec>

      </sequential>

    </parallel>

  </target>

</project>

3. Download and unzip jakarta-tomcat-5.0.28

   http://mirrors.ccs.neu.edu/Apache/dist/jakarta/tomcat-5/v5.0.28/bin/jakarta-
tomcat-5.0.28.zip

4. Configure bash environment; example:

bash> export CATALINA_HOME=d:\\jakarta-tomcat-5.0.28

5. Run like this passing in your classes path:

bash> ant -f test.xml -Dclasses=classes

(Ignore exception thrown trying to stop tomcat since it is not running yet)

Ant process will hang.
Let it run for more than 5 minutes, exceeding the wait timeout; it is hanging 
somewhere.

Also, open a web browser and paste in the http url. Web page opens up and is 
available.

Comment 3 Steve Loughran 2005-10-10 11:31:01 UTC
1. Is this Unix or Windows? The bugrep says Win2K, but the details says bash
which implies unix.

2. On the javacommand, add the attribute inputstring=""
 Does this make the problem go away?

If you are using unix, and (2) works, then this is a duplicate of an existing
problem that we are aware of..if it is windows then it may be a new version of
the  same problem.

Comment 4 Matt Benson 2005-10-10 16:13:10 UTC
(I read "bash" as "cygwin", but that could just be my personal bias.)
Comment 5 Nosa Omorogbe 2005-10-11 15:38:22 UTC
(In reply to comment #3)
> 1. Is this Unix or Windows? The bugrep says Win2K, but the details says bash
> which implies unix.
> 2. On the javacommand, add the attribute inputstring=""
>  Does this make the problem go away?
> If you are using unix, and (2) works, then this is a duplicate of an existing
> problem that we are aware of..if it is windows then it may be a new version of
> the  same problem.

This is Windows; am running Cygwin on Windows.
It sounds like same bug, but on Windows.
It also happens on Windows when ANT is invoked by a parent process like Cruise 
Control.
Adding inputstring="" makes problem go away.
Please, see my "NOTE" in previous comment.
Comment 6 Frank Schwarz 2008-03-02 10:09:34 UTC
I am able to reproduce the problem with Java 5/Java 6 and Ant 1.7.0 under Windows2000 and WindowsXP (but not under Ubuntu 7.04).

The test script will hang (i.e. wait for input) when it entered the run target in sample\build.xml. It will not hang if you add inputstring="" in line 69 in this script.

Process Explorer indicates that one thread in the hanging java process is trying to establish a socket connection.

Attaching a java monitoring tool to the ant process will prevent the script from hanging.

Unfortunately the sample's size exceeds the file limit here, so I will provide it on request by e-mail.
Comment 7 Stefan Bodewig 2008-08-22 04:42:37 UTC

*** This bug has been marked as a duplicate of bug 34461 ***