8067486: Add diagnostics for Exception: Read from closed pipe hang
authorrriggs
Mon, 15 Dec 2014 17:36:20 -0500
changeset 28063 997c263dff16
parent 28062 52b80a88a63b
child 28064 cd22a60e9459
8067486: Add diagnostics for Exception: Read from closed pipe hang Reviewed-by: lancea
jdk/test/java/lang/Runtime/exec/SleepyCat.java
--- a/jdk/test/java/lang/Runtime/exec/SleepyCat.java	Mon Dec 15 12:09:49 2014 -0800
+++ b/jdk/test/java/lang/Runtime/exec/SleepyCat.java	Mon Dec 15 17:36:20 2014 -0500
@@ -22,7 +22,7 @@
  */
 
 /* @test
-   @bug 4843136 4763384
+   @bug 4843136 4763384 8044841
    @summary Various race conditions caused exec'ed processes to have
    extra unused file descriptors, which caused hard-to-reproduce hangs.
    @author Martin Buchholz
@@ -50,6 +50,8 @@
         }
 
         public void run() {
+            dumpState(deathRow);        // before killing the processes dump all the state
+
             timedOut = true;
             destroy(deathRow);
         }
@@ -59,6 +61,37 @@
         }
     }
 
+    /**
+     * Temporary debugging code for intermittent failures.
+     * @param pids the processes to dump status for
+     */
+    static void dumpState(Process... pids) {
+        if (!System.getProperty("os.name").contains("SunOS")) {
+            return;
+        }
+        try {
+            String[] psArgs = {"ps", "-elf"};
+            Process ps = new ProcessBuilder(psArgs).inheritIO().start();
+            ps.waitFor();
+            String[] sfiles = {"pfiles", "self"};
+            Process fds = new ProcessBuilder(sfiles).inheritIO().start();
+            fds.waitFor();
+
+            for (Process p : pids) {
+                if (p == null)
+                    continue;
+                String[] pfiles = {"pfiles", Long.toString(p.getPid())};
+                fds = new ProcessBuilder(pfiles).inheritIO().start();
+                fds.waitFor();
+                String[] pstack = {"pstack", Long.toString(p.getPid())};
+                fds = new ProcessBuilder(pstack).inheritIO().start();
+                fds.waitFor();
+            }
+        } catch (IOException | InterruptedException i) {
+            i.printStackTrace();
+        }
+    }
+
     private static boolean hang1() throws IOException, InterruptedException {
         // Time out was reproducible on Solaris 50% of the time;
         // on Linux 80% of the time.