Log the address and port when binding fails 12/78212/2
authorStephen Kitt <skitt@redhat.com>
Tue, 27 Nov 2018 15:07:09 +0000 (16:07 +0100)
committerStephen Kitt <skitt@redhat.com>
Tue, 27 Nov 2018 16:01:32 +0000 (17:01 +0100)
Currently, when we fail to bind, the error appears in a Netty thread
and is only logged if we have a last-chance logger on the relevant
thread. This patch ensures that TcpHandler and UdpHandler log binding
errors with an informative error message.

Change-Id: I687d84cec09d1ed2389bed9e2e04e50cd1296850
JIRA: OPNFLWPLUG-1054
Signed-off-by: Stephen Kitt <skitt@redhat.com>
openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TcpHandler.java
openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/UdpHandler.java

index 0a48de11c2d37db1d14513091c39a53a7da7a001..4eb67cfd51e6b3b570d613221ce2f9293144e1ec 100644 (file)
@@ -84,6 +84,7 @@ public class TcpHandler implements ServerFacade {
      * Starts server on selected port.
      */
     @Override
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public void run() {
         /*
          * We generally do not perform IO-unrelated tasks, so we want to have
@@ -119,6 +120,10 @@ public class TcpHandler implements ServerFacade {
         } catch (InterruptedException e) {
             LOG.error("Interrupted while binding port {}", port, e);
             return;
+        } catch (Throwable throwable) {
+            // sync() re-throws exceptions declared as Throwable, so the compiler doesn't see them
+            LOG.error("Error while binding address {} and port {}", startupAddress, port, throwable);
+            throw throwable;
         }
 
         try {
index 144037dab7e8be32d94904024adb53e9e886e5fc..ac61d67a7f5dce03966436609c689cbb46fdca44 100644 (file)
@@ -63,6 +63,7 @@ public final class UdpHandler implements ServerFacade {
     }
 
     @Override
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public void run() {
         final ChannelFuture f;
         try {
@@ -78,6 +79,10 @@ public final class UdpHandler implements ServerFacade {
         } catch (InterruptedException e) {
             LOG.error("Interrupted while binding port {}", port, e);
             return;
+        } catch (Throwable throwable) {
+            // sync() re-throws exceptions declared as Throwable, so the compiler doesn't see them
+            LOG.error("Error while binding address {} and port {}", startupAddress, port, throwable);
+            throw throwable;
         }
 
         try {