]> source.dussan.org Git - vaadin-framework.git/commitdiff
Terminate JVM if server.close() has no effect (#12363)
authorLeif Åstrand <leif@vaadin.com>
Tue, 13 Aug 2013 10:17:41 +0000 (13:17 +0300)
committerLeif Åstrand <leif@vaadin.com>
Tue, 13 Aug 2013 10:17:59 +0000 (13:17 +0300)
Change-Id: If024d94d496a6cf2e6f0f342d368ac7bd746de38

uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java

index 070cd2834d55f1791f845226080c1efab9b83792..99f9707479a8eaf34d6925e5805e2d1a71faa0ba 100644 (file)
@@ -26,6 +26,7 @@ import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
@@ -212,8 +213,35 @@ public class DevelopmentServerLauncher {
                             Socket accept = serverSocket.accept();
                             // First stop listening to the port
                             serverSocket.close();
+                            final Thread stopThread = Thread.currentThread();
+
+                            // Start a thread that kills the JVM if
+                            // server.stop() doesn't have any effect
+                            Thread interruptThread = new Thread() {
+                                @Override
+                                public void run() {
+                                    try {
+                                        Thread.sleep(5000);
+                                        if (!server.isStopped()) {
+                                            System.out
+                                                    .println("Jetty still running. Closing JVM.");
+                                            dumpThreadStacks();
+                                            System.exit(-1);
+                                        }
+                                    } catch (InterruptedException e) {
+                                        // Interrupted if server.stop() was
+                                        // successful
+                                    }
+                                }
+                            };
+                            interruptThread.setDaemon(true);
+                            interruptThread.start();
+
                             // Then stop the jetty server
                             server.stop();
+
+                            interruptThread.interrupt();
+
                             // Send a byte to tell the other process that it can
                             // start jetty
                             OutputStream outputStream = accept
@@ -352,4 +380,19 @@ public class DevelopmentServerLauncher {
 
     }
 
+    private static void dumpThreadStacks() {
+        for (Entry<Thread, StackTraceElement[]> entry : Thread
+                .getAllStackTraces().entrySet()) {
+            Thread thread = entry.getKey();
+            StackTraceElement[] stackTraceElements = entry.getValue();
+
+            System.out.println(thread.getName() + " - " + thread.getState());
+            for (StackTraceElement stackTraceElement : stackTraceElements) {
+                System.out.println("    at " + stackTraceElement.toString());
+            }
+            System.out.println();
+        }
+
+    }
+
 }