From 05b961d762dcf1d101d82f60ac89b99e6c802bf6 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 29 Jul 2022 13:23:16 +0200 Subject: [PATCH 1/1] Bump sshd to 2.9.1 https://github.com/apache/mina-sshd/blob/master/docs/changes/2.9.0.md https://github.com/apache/mina-sshd/blob/master/docs/changes/2.9.1.md JIRA: NETCONF-894 Change-Id: I54ecf8d02d4adfea742ce47ac6e164b1df2f6615 Signed-off-by: Samuel Schneider Signed-off-by: Robert Varga --- .../netconf/ssh/SshProxyServer.java | 38 ++++++++++++++----- .../ssh/client/NetconfClientSessionImpl.java | 2 +- netconf/shaded-sshd-jar/pom.xml | 4 +- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServer.java b/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServer.java index 7e192d7364..21c44d4591 100644 --- a/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServer.java +++ b/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServer.java @@ -12,14 +12,17 @@ import static java.util.Objects.requireNonNull; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import io.netty.channel.EventLoopGroup; import java.io.IOException; import java.nio.channels.AsynchronousChannelGroup; import java.time.Duration; import java.util.List; import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; import org.opendaylight.netconf.shaded.sshd.common.FactoryManager; import org.opendaylight.netconf.shaded.sshd.common.NamedFactory; import org.opendaylight.netconf.shaded.sshd.common.RuntimeSshException; @@ -127,26 +130,32 @@ public class SshProxyServer implements AutoCloseable { private abstract static class AbstractNioServiceFactory extends AbstractCloseable implements IoServiceFactory { private final FactoryManager manager; private final AsynchronousChannelGroup group; - + private final ExecutorService resumeTasks; private IoServiceEventListener eventListener; - AbstractNioServiceFactory(final FactoryManager manager, final AsynchronousChannelGroup group) { + AbstractNioServiceFactory(final FactoryManager manager, final AsynchronousChannelGroup group, + final ExecutorService resumeTasks) { this.manager = requireNonNull(manager); this.group = requireNonNull(group); + this.resumeTasks = requireNonNull(resumeTasks); } final AsynchronousChannelGroup group() { return group; } + final ExecutorService resumeTasks() { + return resumeTasks; + } + @Override public final IoConnector createConnector(final IoHandler handler) { - return new Nio2Connector(manager, handler, group); + return new Nio2Connector(manager, handler, group, resumeTasks); } @Override public final IoAcceptor createAcceptor(final IoHandler handler) { - return new Nio2Acceptor(manager, handler, group); + return new Nio2Acceptor(manager, handler, group, resumeTasks); } @Override @@ -164,14 +173,17 @@ public class SshProxyServer implements AutoCloseable { * Based on Nio2ServiceFactory with one addition: injectable executor. */ private static final class NioServiceWithPoolFactory extends AbstractNioServiceFactory { - NioServiceWithPoolFactory(final FactoryManager manager, final AsynchronousChannelGroup group) { - super(manager, group); + NioServiceWithPoolFactory(final FactoryManager manager, final AsynchronousChannelGroup group, + final ExecutorService resumeTasks) { + super(manager, group, resumeTasks); } @Override protected void doCloseImmediately() { try { + resumeTasks().shutdownNow(); group().shutdownNow(); + resumeTasks().awaitTermination(5, TimeUnit.SECONDS); group().awaitTermination(5, TimeUnit.SECONDS); } catch (final IOException | InterruptedException e) { log.debug("Exception caught while closing channel group", e); @@ -182,6 +194,8 @@ public class SshProxyServer implements AutoCloseable { } private static final class NioServiceWithPoolFactoryFactory extends Nio2ServiceFactoryFactory { + private static final AtomicLong COUNTER = new AtomicLong(); + private final ExecutorServiceFacade nioExecutor; NioServiceWithPoolFactoryFactory(final ExecutorService nioExecutor) { @@ -191,7 +205,10 @@ public class SshProxyServer implements AutoCloseable { @Override public IoServiceFactory create(final FactoryManager manager) { try { - return new NioServiceWithPoolFactory(manager, AsynchronousChannelGroup.withThreadPool(nioExecutor)); + return new NioServiceWithPoolFactory(manager, AsynchronousChannelGroup.withThreadPool(nioExecutor), + Executors.newSingleThreadExecutor(new ThreadFactoryBuilder() + .setNameFormat("sshd-resume-read-" + COUNTER.getAndIncrement() + "-%d") + .build())); } catch (final IOException e) { throw new RuntimeSshException("Failed to create channel group", e); } @@ -199,8 +216,9 @@ public class SshProxyServer implements AutoCloseable { } private static final class SharedNioServiceFactory extends AbstractNioServiceFactory { - SharedNioServiceFactory(final FactoryManager manager, final AsynchronousChannelGroup group) { - super(manager, group); + SharedNioServiceFactory(final FactoryManager manager, final AsynchronousChannelGroup group, + final ExecutorService resumeTasks) { + super(manager, group, resumeTasks); } } @@ -213,7 +231,7 @@ public class SshProxyServer implements AutoCloseable { @Override public IoServiceFactory create(final FactoryManager manager) { - return new SharedNioServiceFactory(manager, group); + return new SharedNioServiceFactory(manager, group, Executors.newSingleThreadExecutor()); } } } diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/NetconfClientSessionImpl.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/NetconfClientSessionImpl.java index 6f3492ef1f..411a62889d 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/NetconfClientSessionImpl.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/NetconfClientSessionImpl.java @@ -30,7 +30,7 @@ public class NetconfClientSessionImpl extends ClientSessionImpl implements Netty throws IOException { final NettyAwareChannelSubsystem channel = new NettyAwareChannelSubsystem(subsystem, ctx); final ConnectionService service = getConnectionService(); - final int id = service.registerChannel(channel); + final long id = service.registerChannel(channel); if (log.isDebugEnabled()) { log.debug("createSubsystemChannel({})[{}] created id={}", this, channel.getSubsystem(), id); } diff --git a/netconf/shaded-sshd-jar/pom.xml b/netconf/shaded-sshd-jar/pom.xml index ddeae1e3be..8fda458149 100644 --- a/netconf/shaded-sshd-jar/pom.xml +++ b/netconf/shaded-sshd-jar/pom.xml @@ -32,12 +32,12 @@ org.apache.sshd sshd-osgi - 2.8.0 + 2.9.1 org.apache.sshd sshd-netty - 2.8.0 + 2.9.1 org.apache.sshd -- 2.36.6