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 2018/02/12 06:54:05 UTC

mina-sshd git commit: [SSHD-803] Gracefully close channel output stream when TcpIpServerChannel gracefully closed

Repository: mina-sshd
Updated Branches:
  refs/heads/master a04eaf4fa -> 5a796ebcd


[SSHD-803] Gracefully close channel output stream when TcpIpServerChannel gracefully closed


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

Branch: refs/heads/master
Commit: 5a796ebcd20f46c8b35d06ba5155eab3582ec62e
Parents: a04eaf4
Author: cu0132 <fu...@primeur.com>
Authored: Mon Feb 12 08:53:25 2018 +0200
Committer: Goldstein Lyor <ly...@c-b4.com>
Committed: Mon Feb 12 08:53:59 2018 +0200

----------------------------------------------------------------------
 .../sshd/server/forward/TcpipServerChannel.java | 25 ++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/5a796ebc/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java b/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
index da33d51..6e4195d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
@@ -260,6 +260,27 @@ public class TcpipServerChannel extends AbstractServerChannel {
 
     @Override
     public CloseFuture close(boolean immediately) {
+        boolean debugEnabled = log.isDebugEnabled();
+        /*
+         * In case of graceful shutdown (e.g. when the remote channel is gently closed)
+         * we also need to close the ChannelOutputStream which flushes remaining buffer
+         * and sends SSH_MSG_CHANNEL_EOF back to the client.
+         */
+        if ((!immediately) && (out != null)) {
+            try {
+                if (debugEnabled) {
+                    log.debug("Closing channel output stream of {}", this);
+                }
+
+                out.close();
+            } catch (IOException | RuntimeException ignored) {
+                if (debugEnabled) {
+                    log.debug("{} while closing channel output stream of {}: {}",
+                        ignored.getClass().getSimpleName(), this, ignored.getMessage());
+                }
+            }
+        }
+
         CloseFuture closingFeature = super.close(immediately);
 
         // We also need to dispose of the connector, but unfortunately we
@@ -279,14 +300,14 @@ public class TcpipServerChannel extends AbstractServerChannel {
         return builder().when(closingFeature).run(toString(), () -> {
             executors.submit(() -> {
                 try {
-                    if (log.isDebugEnabled()) {
+                    if (debugEnabled) {
                         log.debug("disposing connector: {} for: {}", connector, TcpipServerChannel.this);
                     }
                     connector.close(immediately);
                 } finally {
                     if (shutdown && (!executors.isShutdown())) {
                         Collection<Runnable> runners = executors.shutdownNow();
-                        if (log.isDebugEnabled()) {
+                        if (debugEnabled) {
                             log.debug("destroy({}) - shutdown executor service - runners count={}",
                                       TcpipServerChannel.this, runners.size());
                         }