You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2015/02/18 15:40:24 UTC
mina-sshd git commit: [SSHD-348] Try to fix the problem with non
closed channels
Repository: mina-sshd
Updated Branches:
refs/heads/master 709aa9327 -> 964e76890
[SSHD-348] Try to fix the problem with non closed channels
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/964e7689
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/964e7689
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/964e7689
Branch: refs/heads/master
Commit: 964e76890cf56da4491199860d0ea8276fbd26a6
Parents: 709aa93
Author: Guillaume Nodet <gn...@apache.org>
Authored: Wed Feb 18 15:40:16 2015 +0100
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Wed Feb 18 15:40:16 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/sshd/common/FactoryManager.java | 7 +++++++
.../apache/sshd/common/channel/AbstractChannel.java | 15 ++++++++++++++-
.../common/session/AbstractConnectionService.java | 1 -
3 files changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/964e7689/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java b/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java
index 8179835..14fd6d6 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java
@@ -79,6 +79,13 @@ public interface FactoryManager {
public static final String DISCONNECT_TIMEOUT = "disconnect-timeout";
/**
+ * Key used to configure the timeout used when writing a close request
+ * on a channel. If the message can not be written before the specified
+ * timeout elapses, the channel will be immediately closed. In milliseconds.
+ */
+ public static final String CHANNEL_CLOSE_TIMEOUT = "channel-close-timeout";
+
+ /**
* Socket backlog.
* See {@link java.nio.channels.AsynchronousServerSocketChannel#bind(java.net.SocketAddress, int)}
*/
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/964e7689/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
index 41a0b4a..c2d4231 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
@@ -21,6 +21,7 @@ package org.apache.sshd.common.channel;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.sshd.common.Channel;
@@ -48,6 +49,8 @@ public abstract class AbstractChannel extends CloseableUtils.AbstractInnerClosea
public static final int DEFAULT_WINDOW_SIZE = 0x200000;
public static final int DEFAULT_PACKET_SIZE = 0x8000;
+ public static final long DEFAULT_CHANNEL_CLOSE_TIMEOUT = 5000;
+
protected static enum GracefulState {
Opened, CloseSent, CloseReceived, Closed
}
@@ -171,7 +174,16 @@ public abstract class AbstractChannel extends CloseableUtils.AbstractInnerClosea
Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_CLOSE);
buffer.putInt(recipient);
try {
- session.writePacket(buffer).addListener(new SshFutureListener<IoWriteFuture>() {
+ long timeout = DEFAULT_CHANNEL_CLOSE_TIMEOUT;
+ String val = getSession().getFactoryManager().getProperties().get(FactoryManager.CHANNEL_CLOSE_TIMEOUT);
+ if (val != null) {
+ try {
+ timeout = Long.parseLong(val);
+ } catch (NumberFormatException e) {
+ // Ignore
+ }
+ }
+ session.writePacket(buffer, timeout, TimeUnit.MILLISECONDS).addListener(new SshFutureListener<IoWriteFuture>() {
public void operationComplete(IoWriteFuture future) {
if (future.isWritten()) {
log.debug("Message SSH_MSG_CHANNEL_CLOSE written on channel {}", AbstractChannel.this);
@@ -181,6 +193,7 @@ public abstract class AbstractChannel extends CloseableUtils.AbstractInnerClosea
gracefulFuture.setClosed();
}
} else {
+ log.debug("Failed to write SSH_MSG_CHANNEL_CLOSE on channel {}", AbstractChannel.this);
AbstractChannel.this.close(true);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/964e7689/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
index 31a5e48..6a709df 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
@@ -261,7 +261,6 @@ public abstract class AbstractConnectionService extends CloseableUtils.AbstractI
public void channelClose(Buffer buffer) throws IOException {
Channel channel = getChannel(buffer);
channel.handleClose();
- unregisterChannel(channel);
}
/**