From e7f9ea2cd02cc8ffb743cff4d07ba7068d1e7c73 Mon Sep 17 00:00:00 2001 From: Tomas Cere Date: Mon, 7 Jan 2019 11:21:09 +0100 Subject: [PATCH] Prevent ssh hang during shutdown Add a reference listener for netty executor service provided by blueprint so we can close ssh servers while the bundle still exists. This prevents the hang seen during shutdown since the executor was being shutdown before the mdsal-netconf-ssh. JIRA: NETCONF-577 Change-Id: I062c9e8afb349817435ea0b1dde796a54ebb22d2 Signed-off-by: Tomas Cere --- netconf/mdsal-netconf-ssh/pom.xml | 5 +++++ .../org/opendaylight/blueprint/netconf-ssh.xml | 5 ++++- .../netconf/ssh/NetconfNorthboundSshServer.java | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/netconf/mdsal-netconf-ssh/pom.xml b/netconf/mdsal-netconf-ssh/pom.xml index ff13ec2eaf..2e9a06a44b 100644 --- a/netconf/mdsal-netconf-ssh/pom.xml +++ b/netconf/mdsal-netconf-ssh/pom.xml @@ -27,6 +27,11 @@ ${project.groupId} netconf-ssh + + org.apache.aries.blueprint + org.apache.aries.blueprint.core + provided + diff --git a/netconf/mdsal-netconf-ssh/src/main/resources/org/opendaylight/blueprint/netconf-ssh.xml b/netconf/mdsal-netconf-ssh/src/main/resources/org/opendaylight/blueprint/netconf-ssh.xml index 9d5d3ed409..1b1278edf6 100755 --- a/netconf/mdsal-netconf-ssh/src/main/resources/org/opendaylight/blueprint/netconf-ssh.xml +++ b/netconf/mdsal-netconf-ssh/src/main/resources/org/opendaylight/blueprint/netconf-ssh.xml @@ -13,9 +13,12 @@ - + + + + diff --git a/netconf/netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/NetconfNorthboundSshServer.java b/netconf/netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/NetconfNorthboundSshServer.java index f478029323..fa5337c6c8 100644 --- a/netconf/netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/NetconfNorthboundSshServer.java +++ b/netconf/netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/NetconfNorthboundSshServer.java @@ -21,6 +21,7 @@ import org.opendaylight.netconf.auth.AuthProvider; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder; +import org.osgi.framework.ServiceReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -87,4 +88,18 @@ public class NetconfNorthboundSshServer { localServer.cancel(true); } } + + /* + * Called when the underlying reference to EventExecutor is about to be removed from the container allowing + * us to close the ssh server while it still exists. + */ + public void unbind(final ServiceReference reference) { + LOG.debug("EventExecutor is being removed, closing netconf ssh server. {}", reference); + + try { + close(); + } catch (final IOException e) { + LOG.error("Closing of ssh server failed while unbinding reference listener.", e); + } + } } -- 2.36.6