]> source.dussan.org Git - gitblit.git/commitdiff
if failed to bind to port, don't use socket 277/head
authorJoel Johnson <joel.johnson@issinc.com>
Fri, 26 Jun 2015 21:47:44 +0000 (15:47 -0600)
committerJoel Johnson <joel.johnson@issinc.com>
Mon, 29 Jun 2015 16:17:52 +0000 (10:17 -0600)
src/main/java/com/gitblit/GitBlitServer.java

index a1fd071f68c5a2cd6dfc2afb3d37c1efda06b70b..d56d9c0c6b7153231dd4138df0f1672aa3d20ae3 100644 (file)
@@ -509,22 +509,25 @@ public class GitBlitServer {
 
                @Override
                public void run() {
-                       logger.info("Shutdown Monitor listening on port " + socket.getLocalPort());
-                       Socket accept;
-                       try {
-                               accept = socket.accept();
-                               BufferedReader reader = new BufferedReader(new InputStreamReader(
-                                               accept.getInputStream()));
-                               reader.readLine();
-                               logger.info(Constants.BORDER);
-                               logger.info("Stopping " + Constants.NAME);
-                               logger.info(Constants.BORDER);
-                               server.stop();
-                               server.setStopAtShutdown(false);
-                               accept.close();
-                               socket.close();
-                       } catch (Exception e) {
-                               logger.warn("Failed to shutdown Jetty", e);
+                       // Only run if the socket was able to be created (not already in use, failed to bind, etc.)
+                       if (null != socket) {
+                               logger.info("Shutdown Monitor listening on port " + socket.getLocalPort());
+                               Socket accept;
+                               try {
+                                       accept = socket.accept();
+                                       BufferedReader reader = new BufferedReader(new InputStreamReader(
+                                                       accept.getInputStream()));
+                                       reader.readLine();
+                                       logger.info(Constants.BORDER);
+                                       logger.info("Stopping " + Constants.NAME);
+                                       logger.info(Constants.BORDER);
+                                       server.stop();
+                                       server.setStopAtShutdown(false);
+                                       accept.close();
+                                       socket.close();
+                               } catch (Exception e) {
+                                       logger.warn("Failed to shutdown Jetty", e);
+                               }
                        }
                }
        }