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 cf4ec213c296bbd103dfe75f7650670b008aa041..ad8b25ff2156d8e937d65d054b41b1e3f34c159e 100644 (file)
@@ -52,15 +52,8 @@ public class SshClientAdapter implements Runnable {
     }
 
     public void run() {
     }
 
     public void run() {
-        SshSession session;
-        try {
-            session = sshClient.openSession();
-        } catch (IOException e) {
-            logger.error("Cannot establish session", e);
-            sshClient.close();
-            return;
-        }
         try {
         try {
+            SshSession session = sshClient.openSession();
             invoker.invoke(session);
             InputStream stdOut = session.getStdout();
             session.getStderr();
             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.
 
         } 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);
             // 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());
 
     private void writeImpl(ByteBuf message) throws IOException {
         message.getBytes(0, stdIn, message.readableBytes());
+        message.release();
         stdIn.flush();
     }
 
         stdIn.flush();
     }
 
index d97990a5e6f304724b150a40b9e92c8203a3c28a..626ebe937e6942396d695369435cde67f90beda2 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.
  */
 /**
  * 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;
 }
 public class VirtualSocketException extends RuntimeException {
     private static final long serialVersionUID = 1L;
 }