Hi All, I have encountered what I believe to be a bug in the Sun JVM (1.4.1 at least). This causes Process.waitFor() and Process.exitValue() to hang intermittently. As CGIServlet uses process.exitValue(), I would expect this bug to also cause this servlet to intermittently hang.
Note that this is NOT due to filling STDOUT/STDERR pipes of the externally executed application (http://developer.java.sun.com/developer/bugParade/bugs/4109888.html and friends). Firstly, has anyone experienced hangs with CGIServlet? Secondly, would someone here be willing to help me out by trying the attached code to verify that the problem can be duplicated? I submitted a bug to Sun in November 2002, and in Feb 2003 received a "cannot reproduce" mail. However I can reproduce it at will. So can at least one of my clients :-( I can reliably duplicate the issue on the following systems: * Mandrake Linux 9.0 on x86: java version "1.4.1_01" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01) Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode) * RedHat Linux 7.2 on x86: java version "1.4.1_01" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01) Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode) * Mandrake Linux 9.0 with Blackdown linux 1.4.1: java version "1.4.1" Java(TM) 2 Runtime Environment, Standard Edition (build Blackdown-1.4.1-01) Java HotSpot(TM) Client VM (build Blackdown-1.4.1-01, mixed mode) Exactly the same .class file (compiled with the Sun JDK) works correctly when run on the following: * Mandrake Linux 9.0 with IBM JVM 1.4.0: java version "1.4.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0) Classic VM (build 1.4.0, J2RE 1.4.0 IBM build cxia32140-20020917a (JIT enabled: jitc)) * IBM AIX 5 with IBM JVM 1.4.0: java version "1.4.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0) Classic VM (build 1.4.0, J2RE 1.4.0 IBM AIX build ca1401-20021126 (JIT enabled: jitc)) ----------------------- How to run the test app: (a) save "runme" script, make executable (chmod +x) (b) compile HangMe.java (c) java -cp . HangMe runme The application will print "about to waitFor .. waitFor completed" about 18 times. Then the text "about to waitFor" will be displayed and the application will hang. Don't forget the "runme" parameter to tell the app which external process to invoke - command-line error handling is not implemented :-) I have a variant of this app which uses a combination of Process.exitValue(), catch-clause, and sleep() to try to detect external process termination, but this hangs too, presumably due to the same underlying issue. This is basically the approach taken by CGIServlet... Regards, Simon Kitching The Electronic Commerce Network Ltd.
#!/bin/sh #echo "runme" >> runme.out exit 0
import java.io.File; import java.io.IOException; class HangMe { private static void log_debug(String s) { System.out.println("DEBUG:" + s); } private static void log_debug(String s, Throwable t) { System.out.println("DEBUG:" + s + ":" + t.toString()); t.printStackTrace(); } private static void log_warn(String s) { System.out.println("WARN:" + s); } private static void log_warn(String s, Throwable t) { System.out.println("WARN:" + s + ":" + t.toString()); t.printStackTrace(); } public static void runIt(String appname) throws Exception { String[] envarray = new String[0]; String[] cmdarray = new String[1]; cmdarray[0] = appname; File workingDir = new File("."); Process proc; try { proc = Runtime.getRuntime().exec(cmdarray, envarray, workingDir); } catch(SecurityException se) { log_warn("Permission refused to run command", se); throw new Exception( "Permission refused to run command", se); } catch(IOException ioe) { log_warn("Unable to run command", ioe); throw new Exception( "Unable to run command", ioe); } // check process exit status try { log_debug("about to waitFor.."); proc.waitFor(); log_debug("waitFor completed."); } catch(InterruptedException e4) { throw new Exception("interrupted while waiting for app to end"); } int exitStatus = proc.exitValue(); if (exitStatus == 0) { // success log_debug("application executed successfully"); } else { log_debug("application failed"); } } public static void main(String[] args) throws Exception { String appname=args[0]; for(;;) { runIt(appname); } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]