changeset 1840:7db324f3b3f7

Better command channel cleanup I have noticed sometimes that if the command channel port is already bound, the command channel process does not shut down properly and remains running after the agent exits. This patch modifies the error handling to release Netty's resources when an exception occurs, without relying on the shutdown hook. Reviewed-by: jerboaa, omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-November/016821.html PR2731
author Elliott Baron <ebaron@redhat.com>
date Tue, 17 Nov 2015 18:09:16 -0500
parents 387b2f113734
children 6877024d66eb
files agent/command-server/src/main/java/com/redhat/thermostat/agent/command/server/internal/CommandChannelServerMain.java
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/agent/command-server/src/main/java/com/redhat/thermostat/agent/command/server/internal/CommandChannelServerMain.java	Tue Nov 10 13:12:42 2015 -0500
+++ b/agent/command-server/src/main/java/com/redhat/thermostat/agent/command/server/internal/CommandChannelServerMain.java	Tue Nov 17 18:09:16 2015 -0500
@@ -51,7 +51,8 @@
     private static ShutdownHookHandler shutdownHandler = new ShutdownHookHandler();
     private static Sleeper sleeper = new Sleeper();
     private static LoggingInitializer logInit = new LoggingInitializer();
-    
+    private static CommandChannelServerImpl impl = null;
+
     // TODO Add some keep alive check
     public static void main(String[] args) {
         if (args.length != 2) {
@@ -73,7 +74,7 @@
         try {
             SSLConfiguration config = sslConfParser.parse(System.in);
             
-            final CommandChannelServerImpl impl = serverCreator.createServer(config);
+            impl = serverCreator.createServer(config);
             
             // Start listening on server
             impl.startListening(hostname, port);
@@ -89,6 +90,9 @@
         } catch (IOException e) {
             System.err.println("Failed to start command channel server");
             e.printStackTrace();
+            if (impl != null) {
+                impl.stopListening();
+            }
         }
     }