Bug:1238 - Revert changes to SshClientAdapter. 93/8293/1
authorTomas Olvecky <tolvecky@cisco.com>
Tue, 24 Jun 2014 10:57:14 +0000 (12:57 +0200)
committerTomas Olvecky <tolvecky@cisco.com>
Tue, 24 Jun 2014 10:57:14 +0000 (12:57 +0200)
Fix bug introduced in 412e6b4 by reverting back to previous state.
Also fix a resource leak in writeImpl.

Change-Id: If43741071d1471280491888078f342bc33269c5f
Signed-off-by: Tomas Olvecky <tolvecky@cisco.com>
opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/SshClientAdapter.java
opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/virtualsocket/VirtualSocketException.java

index cf4ec21..ad8b25f 100644 (file)
@@ -52,15 +52,8 @@ public class SshClientAdapter implements Runnable {
     }
 
     public void run() {
-        SshSession session;
-        try {
-            session = sshClient.openSession();
-        } catch (IOException e) {
-            logger.error("Cannot establish session", e);
-            sshClient.close();
-            return;
-        }
         try {
+            SshSession session = sshClient.openSession();
             invoker.invoke(session);
             InputStream stdOut = session.getStdout();
             session.getStderr();
@@ -90,6 +83,8 @@ public class SshClientAdapter implements Runnable {
 
         } catch (VirtualSocketException e) {
             // Netty closed connection prematurely.
+            // Or maybe tried to open ganymed connection without having initialized session
+            // (ctx.channel().remoteAddress() is null)
             // Just pass and move on.
         } catch (Exception e) {
             logger.error("Unexpected exception", e);
@@ -117,6 +112,7 @@ public class SshClientAdapter implements Runnable {
 
     private void writeImpl(ByteBuf message) throws IOException {
         message.getBytes(0, stdIn, message.readableBytes());
+        message.release();
         stdIn.flush();
     }
 
index d97990a..626ebe9 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.controller.netconf.nettyutil.handler.ssh.virtualsocket;
 /**
  * Exception class which provides notification about exceptional situations at the virtual socket layer.
  */
+// FIXME: Switch to checked exception, create a runtime exception to workaround Socket API
 public class VirtualSocketException extends RuntimeException {
     private static final long serialVersionUID = 1L;
 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.