Log the address and port on bind errors 59/78259/1
authorStephen Kitt <skitt@redhat.com>
Wed, 28 Nov 2018 09:23:02 +0000 (10:23 +0100)
committerJakub Morvay <jakub.morvay@gmail.com>
Wed, 28 Nov 2018 13:35:16 +0000 (13:35 +0000)
This ensures the address and port are available in the logs when we
fail to bind.

Change-Id: I100f68112d90573333340b4dc3e0a6f73c8ad90a
JIRA: NETCONF-585
Signed-off-by: Stephen Kitt <skitt@redhat.com>
(cherry picked from commit 1fca5bf02873a124ea0dfcf91ea44ac9bc57acd4)

netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/NetconfCallHomeServer.java
netconf/netconf-tcp/src/main/java/org/opendaylight/netconf/tcp/netty/ProxyServer.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/websockets/WebSocketServer.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/websockets/WebSocketServer.java

index fbc996a7a84383308517fe77f09af20cfe5e9ba8..3c561262124d4fa5c91dde9b6112a8805a4b58ef 100644 (file)
@@ -181,7 +181,7 @@ public class NetconfCallHomeServer implements AutoCloseable, ServerKeyVerifier {
             client.start();
             acceptor.bind(bindAddress);
         } catch (IOException e) {
-            LOG.error("Unable to start NETCONF CallHome Service", e);
+            LOG.error("Unable to start NETCONF CallHome Service on {}", bindAddress, e);
             throw e;
         }
     }
index feabd71cf079bfa333fb9d66d1200f830ce4c6dc..9e5e175654922aca8e62c794f467c38a809ab475 100644 (file)
@@ -21,12 +21,17 @@ import io.netty.channel.socket.nio.NioServerSocketChannel;
 import io.netty.handler.logging.LogLevel;
 import io.netty.handler.logging.LoggingHandler;
 import java.net.InetSocketAddress;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ProxyServer implements AutoCloseable {
+    private static final Logger LOG = LoggerFactory.getLogger(ProxyServer.class);
+
     private final EventLoopGroup bossGroup = new NioEventLoopGroup();
     private final EventLoopGroup workerGroup = new NioEventLoopGroup();
     private final ChannelFuture channelFuture;
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public ProxyServer(InetSocketAddress address, final LocalAddress localAddress) {
         // Configure the server.
         final Bootstrap clientBootstrap = new Bootstrap();
@@ -44,7 +49,13 @@ public class ProxyServer implements AutoCloseable {
                 });
 
         // Start the server.
-        channelFuture = serverBootstrap.bind(address).syncUninterruptibly();
+        try {
+            channelFuture = serverBootstrap.bind(address).syncUninterruptibly();
+        } catch (Throwable throwable) {
+            // sync() re-throws exceptions declared as Throwable, so the compiler doesn't see them
+            LOG.error("Error while binding to address {}", address, throwable);
+            throw throwable;
+        }
     }
 
     @Override
index b8093dcb7a38077f6da9a2646ab5e493f4434f3a..68612749ae65de79f2b1b734f5999c45cd6d348e 100644 (file)
@@ -107,6 +107,7 @@ public final class WebSocketServer implements Runnable {
     }
 
     @Override
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public void run() {
         bossGroup = new NioEventLoopGroup();
         workerGroup = new NioEventLoopGroup();
@@ -121,6 +122,10 @@ public final class WebSocketServer implements Runnable {
             channel.closeFuture().sync();
         } catch (final InterruptedException e) {
             LOG.error("Web socket server encountered an error during startup attempt on port {}", port, e);
+        } catch (Throwable throwable) {
+            // sync() re-throws exceptions declared as Throwable, so the compiler doesn't see them
+            LOG.error("Error while binding to address {}, port {}", address, port, throwable);
+            throw throwable;
         } finally {
             stop();
         }
index 029cb27f78672c465cf247520b800d8a306d0953..54b11e040e4a1c1102447a3b2f7713de4d2e1c6b 100644 (file)
@@ -82,6 +82,7 @@ public final class WebSocketServer implements Runnable {
     }
 
     @Override
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public void run() {
         bossGroup = new NioEventLoopGroup();
         workerGroup = new NioEventLoopGroup();
@@ -96,6 +97,10 @@ public final class WebSocketServer implements Runnable {
             channel.closeFuture().sync();
         } catch (final InterruptedException e) {
             LOG.error("Web socket server encountered an error during startup attempt on port {}", port, e);
+        } catch (Throwable throwable) {
+            // sync() re-throws exceptions declared as Throwable, so the compiler doesn't see them
+            LOG.error("Error while binding to port {}", port, throwable);
+            throw throwable;
         } finally {
             stop();
         }