You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2017/11/17 09:47:34 UTC

mina-sshd git commit: [SSHD-743] Nio2Session sporadically leaks exceptions from nio2 threads

Repository: mina-sshd
Updated Branches:
  refs/heads/master 96f5f3cef -> bcc3f0cd8


[SSHD-743] Nio2Session sporadically leaks exceptions from nio2 threads


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

Branch: refs/heads/master
Commit: bcc3f0cd8a23528b555188d3cb0672d76bddf97c
Parents: 96f5f3c
Author: Goldstein Lyor <ly...@c-b4.com>
Authored: Thu Nov 16 15:00:02 2017 +0200
Committer: Lyor Goldstein <ly...@gmail.com>
Committed: Fri Nov 17 11:49:12 2017 +0200

----------------------------------------------------------------------
 .../apache/sshd/common/io/nio2/Nio2Session.java   | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bcc3f0cd/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java
index 5285d7b..d86ee34 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java
@@ -274,7 +274,7 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
         doReadCycle(buffer, completion);
     }
 
-    protected Nio2CompletionHandler<Integer, Object> createReadCycleCompletionHandler(final ByteBuffer buffer, final Readable bufReader) {
+    protected Nio2CompletionHandler<Integer, Object> createReadCycleCompletionHandler(ByteBuffer buffer, Readable bufReader) {
         return new Nio2CompletionHandler<Integer, Object>() {
             @Override
             protected void onCompleted(Integer result, Object attachment) {
@@ -348,6 +348,7 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
             doWriteCycle(buffer, handler);
         } catch (Throwable e) {
             future.setWritten();
+
             if (e instanceof RuntimeException) {
                 throw (RuntimeException) e;
             } else {
@@ -363,8 +364,8 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
     }
 
     protected Nio2CompletionHandler<Integer, Object> createWriteCycleCompletionHandler(
-            final Nio2DefaultIoWriteFuture future, final AsynchronousSocketChannel socket, final ByteBuffer buffer) {
-        final int writeLen = buffer.remaining();
+            Nio2DefaultIoWriteFuture future, AsynchronousSocketChannel socket, ByteBuffer buffer) {
+        int writeLen = buffer.remaining();
         return new Nio2CompletionHandler<Integer, Object>() {
             @Override
             protected void onCompleted(Integer result, Object attachment) {
@@ -417,7 +418,16 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
         }
         future.setException(exc);
         exceptionCaught(exc);
-        finishWrite(future);
+
+        // see SSHD-743
+        try {
+            finishWrite(future);
+        } catch (RuntimeException e) {
+            if (log.isTraceEnabled()) {
+                log.trace("handleWriteCycleFailure({}) failed ({}) to finish writing: {}",
+                        this, e.getClass().getSimpleName(), e.getMessage());
+            }
+        }
     }
 
     protected void finishWrite(Nio2DefaultIoWriteFuture future) {