You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by we...@apache.org on 2015/11/06 17:46:26 UTC

incubator-reef git commit: [REEF-446] Throw an Exception when no port can be bound

Repository: incubator-reef
Updated Branches:
  refs/heads/master 3a297b691 -> f2886940b


[REEF-446] Throw an Exception when no port can be bound

This patch:
  * Throws IllegalStateException if the tcpPortProvider runs out of free ports
  * In the catch clause, wraps the exception into RuntimeExceptions, logs the
    cause and rethrows

JIRA:
  [REEF-446](https://issues.apache.org/jira/browse/REEF-446)

Pull request:
  This closes #613


Project: http://git-wip-us.apache.org/repos/asf/incubator-reef/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-reef/commit/f2886940
Tree: http://git-wip-us.apache.org/repos/asf/incubator-reef/tree/f2886940
Diff: http://git-wip-us.apache.org/repos/asf/incubator-reef/diff/f2886940

Branch: refs/heads/master
Commit: f2886940ba84386236afa52f1b8a2baa245ec44b
Parents: 3a297b6
Author: sergey.dudoladov@tu-berlin.de <se...@tu-berlin.de>
Authored: Wed Nov 4 13:57:36 2015 +0100
Committer: Markus Weimer <we...@apache.org>
Committed: Fri Nov 6 08:46:02 2015 -0800

----------------------------------------------------------------------
 .../remote/transport/netty/NettyMessagingTransport.java | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/f2886940/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/remote/transport/netty/NettyMessagingTransport.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/remote/transport/netty/NettyMessagingTransport.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/remote/transport/netty/NettyMessagingTransport.java
index f47665e..22d0c49 100644
--- a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/remote/transport/netty/NettyMessagingTransport.java
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/remote/transport/netty/NettyMessagingTransport.java
@@ -164,7 +164,7 @@ public class NettyMessagingTransport implements Transport {
         final Iterator<Integer> ports = tcpPortProvider.iterator();
         while (acceptorFound == null) {
           if (!ports.hasNext()) {
-            break;
+            throw new IllegalStateException("tcpPortProvider cannot find a free port.");
           }
           p = ports.next();
           LOG.log(Level.FINEST, "Try port {0}", p);
@@ -179,6 +179,16 @@ public class NettyMessagingTransport implements Transport {
           }
         }
       }
+    } catch (final IllegalStateException ex) {
+      final RuntimeException transportException =
+                new TransportRuntimeException("tcpPortProvider failed to return free ports.");
+      LOG.log(Level.SEVERE, "Cannot find a free port with " + tcpPortProvider, transportException);
+
+      this.clientWorkerGroup.shutdownGracefully();
+      this.serverBossGroup.shutdownGracefully();
+      this.serverWorkerGroup.shutdownGracefully();
+      throw transportException;
+
     } catch (final Exception ex) {
       final RuntimeException transportException =
           new TransportRuntimeException("Cannot bind to port " + p);