You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by el...@apache.org on 2017/10/27 13:49:20 UTC

mina git commit: Added the patch suggested by Jonathan Valliere : when the accept() throws an exception, we introduce a Thread.sleep(50) so that the select() does not spin like crazy. See DIRMINA-1060

Repository: mina
Updated Branches:
  refs/heads/2.0 f67ccd7a5 -> 2494b787b


Added the patch suggested by Jonathan Valliere : when the accept()
throws an exception, we introduce a Thread.sleep(50) so that the
select() does not spin like crazy. See DIRMINA-1060

Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/2494b787
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/2494b787
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/2494b787

Branch: refs/heads/2.0
Commit: 2494b787bc0dfd1d6126a36dec85de666b8abeaf
Parents: f67ccd7
Author: Emmanuel Lécharny <el...@symas.com>
Authored: Fri Oct 27 15:49:16 2017 +0200
Committer: Emmanuel Lécharny <el...@symas.com>
Committed: Fri Oct 27 15:49:16 2017 +0200

----------------------------------------------------------------------
 .../transport/socket/nio/NioSocketAcceptor.java | 24 ++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/2494b787/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java
index 947a2a8..101b1a8 100644
--- a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java
+++ b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java
@@ -190,13 +190,29 @@ implements SocketAcceptor {
         }
 
         // accept the connection from the client
-        SocketChannel ch = handle.accept();
+        try {
+            SocketChannel ch = handle.accept();
+    
+            if (ch == null) {
+                return null;
+            }
+
+            return new NioSocketSession(this, processor, ch);
+        } catch (Throwable t) {
+            LOGGER.error("Error Calling Accept on Socket - Sleeping Acceptor Thread. Check the ulimit parameter", t);
+            try {
+                // Sleep 50 ms, so that the select does not spin like crazy doing nothing but eating CPU
+                // This is typically what will happen if we don't have any more File handle on the server
+                // Check the ulimit parameter
+                // NOTE : this is a workaround, there is no way we can handle this exception in any smarter way...
+                Thread.sleep(50L);
+            } catch (InterruptedException ie) {
+                // Nothing to do
+            }
 
-        if (ch == null) {
+            // No session when we have met an exception
             return null;
         }
-
-        return new NioSocketSession(this, processor, ch);
     }
 
     /**