dev@glassfish.java.net

Re: broken pipe when running asadmin

From: Bobby Bissett <Robert.Bissett_at_Sun.COM>
Date: Wed, 02 Sep 2009 21:50:30 -0400

> Are you on Windows Vista by any chance?
> I think there was an exception while closing streams ...

Nope, Mac OS. I took a look at the bug, and I don't have anything to
add. To answer Bill's question, here's the code, partially. I've
removed some unrelated bits to make it readable, and all the comments
are specific to this email (they're not the original comments in my
code):

         commandString = // asadmin call or java -jar. no issues with
the java -jar version
         final long JOIN_TIMEOUT = 4000;
         try {
             Process proc = Runtime.getRuntime().exec(commandString);

             // this class is shown below
             StreamWatcher errWatcher =
                 new StreamWatcher(proc.getErrorStream(), "ERR");
             StreamWatcher outWatcher =
                 new StreamWatcher(proc.getInputStream(), "OUT");
             errWatcher.start();
             outWatcher.start();

             exitValue = proc.waitFor();
             logger.fine("Return value from process: " +
exitValue); // this is also returned to caller
             errWatcher.join(JOIN_TIMEOUT);
             outWatcher.join(JOIN_TIMEOUT);
         } catch (Exception e) {
             // etc
         }

     private static class StreamWatcher extends Thread {
         private final BufferedReader reader;

         // I only have the name in here because it was helpful for
debugging
         public StreamWatcher(InputStream stream, String name) {
             super(name);
             reader = new BufferedReader(new InputStreamReader(stream));
         }

         @Override
         public void run() {
             try {
                 String line = reader.readLine();
                 while (line != null) {
                     // there is a logging handler that gets this and
puts it in the GUI if
                     // the level is > FINE
                     logger.info(getName() + ": " + line);
                     line = reader.readLine();
                     // I've tried with and without this, and I saw
more output with it
                     // looks like something timing related
                     Thread.sleep(2);
                 }
             } catch (Throwable t) {
                 // etc
             } finally {
                 try {
                     reader.close();
                 } catch (Throwable ioe) {
                     // not much
                 }
             }
         }

I think I may have hit a timing issue in the code originally without
the Thread.sleep(2), but what I don't quite get is how, even with no
Java processes running, there is still a pipe issue. My build of the
server worked fine originally: no problem calling asadmin. But once
the above code ran and failed with a pipe issue, then I couldn't start
asadmin from the command line.

For what it's worth, here is the output captured by the above.
Everything that starts with ERR: or OUT: is from the appropriate input
stream from the process:

Executing command: /Users/bobby/servers/glassfishv3/glassfish/bin/
asadmin start-domain -v --domaindir /Users/bobby/servers/glassfishv3/
glassfish/domains domain1
OUT:
ERR: Sep 2, 2009 9:46:43 PM
com.sun.enterprise.admin.launcher.GFLauncherLogger info
ERR: INFO: JVM invocation command line:
ERR: /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin/
java
ERR: -cp
ERR: /Users/bobby/servers/glassfishv3/glassfish/modules/glassfish.jar
ERR: -XX:+UnlockDiagnosticVMOptions
ERR: -XX:MaxPermSize=192m
ERR: -XX:NewRatio=2
ERR: -XX:+LogVMOutput
ERR: -XX:LogFile=/Users/bobby/servers/glassfishv3/glassfish/domains/
domain1/logs/jvm.log
ERR: -Xmx512m
ERR: -client
ERR: -javaagent:/Users/bobby/servers/glassfishv3/glassfish/lib/monitor/
btrace-agent.jar=unsafe=true
ERR: -Djdbc.drivers=org.apache.derby.jdbc.ClientDriver
ERR: -Djavax.net.ssl.trustStore=/Users/bobby/servers/glassfishv3/
glassfish/domains/domain1/config/cacerts.jks
ERR: -Djavax.net.ssl.keyStore=/Users/bobby/servers/glassfishv3/
glassfish/domains/domain1/config/keystore.jks
ERR: -Djava.security.policy=/Users/bobby/servers/glassfishv3/glassfish/
domains/domain1/config/server.policy
ERR: -Dcom.sun.aas.instanceRoot=/Users/bobby/servers/glassfishv3/
glassfish/domains/domain1
ERR: -
Dcom
.sun
.enterprise
.config
.config_environment_factory_class
=com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory
ERR: -DANTLR_USE_DIRECT_CLASS_LOADING=true
ERR: -Djava.security.auth.login.config=/Users/bobby/servers/
glassfishv3/glassfish/domains/domain1/config/login.conf
ERR: -Djava.endorsed.dirs=/Users/bobby/servers/glassfishv3/glassfish/
lib/endorsed
ERR: -Dcom.sun.aas.installRoot=/Users/bobby/servers/glassfishv3/
glassfish
ERR: -Djava.ext.dirs=/System/Library/Frameworks/JavaVM.framework/
Versions/1.6/Home/lib/ext:/System/Library/Frameworks/JavaVM.framework/
Versions/1.6/Home/jre/lib/ext:/Users/bobby/servers/glassfishv3/
glassfish/domains/domain1/lib/ext:/Users/bobby/servers/glassfishv3/
javadb/lib
ERR: -Djava.library.path=/Users/bobby/servers/glassfishv3/glassfish/
lib:/Users/bobby/servers/glassfishv3/glassfish:/Library/Java/
Extensions:/System/Library/Java/Extensions:/usr/lib/java
ERR: com.sun.enterprise.glassfish.bootstrap.ASMain
ERR: -domainname
ERR: domain1
ERR: -asadmin-args
ERR: start-domain,,,-v,,,--domaindir,,,/Users/bobby/servers/
glassfishv3/glassfish/domains,,,domain1
ERR: -instancename
ERR: server
ERR: -verbose
ERR: true
ERR: -debug
ERR: false
ERR: -asadmin-classpath
ERR: /Users/bobby/servers/glassfishv3/glassfish/modules/admin-cli.jar
ERR: -asadmin-classname
ERR: com.sun.enterprise.admin.cli.AsadminMain
ERR: -upgrade
ERR: false
ERR: -domaindir
ERR: /Users/bobby/servers/glassfishv3/glassfish/domains/domain1
ERR: -read-stdin
ERR: true
OUT: Error occurred during initialization of VM
ERR: Error opening zip file or JAR manifest missing : /Users/bobby/
servers/glassfishv3/glassfish/lib/monitor/btrace-agent.jar
OUT: agent library failed to init: instrument
ERR: JVM failed to start: java.io.IOException: Broken pipe
OUT: Command start-domain failed.

So I thought the broken pipe was just an issue in my code that I
wasn't handling the process failing correctly. But I just don't know
enough about, well, computers, to see how I'm getting the pipe issues
even after Java exits and I try from the command line.

Cheers,
Bobby