Bug 311368 - RemoteCommandShellOperation.sendCommand() doesn't call finish handler after physical disconnect / reconnect
Summary: RemoteCommandShellOperation.sendCommand() doesn't call finish handler after p...
Status: NEW
Alias: None
Product: Target Management
Classification: Tools
Component: RSE (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: dsdp.tm.rse-inbox CLA
QA Contact: Martin Oberhuber CLA
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2010-05-03 08:45 EDT by Loganathan CLA
Modified: 2010-05-04 08:23 EDT (History)
0 users

See Also:


Attachments
Infinite read action by TerminalServiceOutputReader. (163.96 KB, image/png)
2010-05-03 08:51 EDT, Loganathan CLA
no flags Details
The wrapper that is used to send and handle remote commands (5.37 KB, application/octet-stream)
2010-05-04 08:21 EDT, Loganathan CLA
no flags Details
The MyRemoteCommandShellOperation which mangages remote commands. (3.10 KB, application/octet-stream)
2010-05-04 08:23 EDT, Loganathan CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Loganathan CLA 2010-05-03 08:45:39 EDT
Build Identifier: M20080911-1700

I'm using an instance of extended type of RemoteCommandShellOperation to send commands to my remote SSH host. At proper connections, the sendCommand(String) method properly results in invocation of handle handleCommandFinished(String) method. But when I disconnect the connection physically and reconnect, and send command with the RemoteCommandShellOperation instance, it does not invoke the handleCommandFinished(String) or handOutputChanged(String). Here no doubt with the proper reconnection(Checked in the debug mode).

Note: In both the case, prior to sending command, I'm using the RemoteCommandShellOperation.run() to activate the remote command shell if the shell is not active.

After seeing in debug mode, it seems that the after the disconnect and reconnect actions, the RemoteCommandShellOperation.sendCommand(String) works fine but the invocation of RemoteCommandShellOperation.handCommandFinished(String) or RemoteCommandShellOperation.handOutputChanged(String)is never done by the TerminalServiceShellOutputReader. 

Reproducible: Always

Steps to Reproduce:
1.Have proper connections, use RemoteCommandShellOperation.sendCommand(String). This invokes RemoteCommandShellOperation.handCommandShell(String) properly.
2. Physically disconnect and reconnect the remote system.
3. Use RemoteCommandShellOperation.sendCommand(String). This doesn't invoke RemoteCommandShellOperation.handCommandFinished(String) or RemoteCommandShellOperation.handOutputChanged(String) properly.

Note: In both the case, prior to sending command, use the RemoteCommandShellOperation.run() to activate the remote command shell if the shell is not active.
Comment 1 Loganathan CLA 2010-05-03 08:51:25 EDT
Created attachment 166770 [details]
Infinite read action by TerminalServiceOutputReader.

This image shows that in debug mode, after disconnect & reconnect action, and after calling the sendCommand(String), the TerminalServiceOutputReader stops infinitely at the read() method.
Comment 2 Loganathan CLA 2010-05-04 01:37:45 EDT
Here, after the connection disconnect and reconnect actions, if I don't use the same RemoteCommandShellOperation instance and use a new instance to send commands, there is no problem in receiving the invocation of handleCommandFinished() and handleOutputChanged() methods. But the same RemoteCommandShellOperation instance becomes unusable after the connection disconnect and reconnect actions.
Comment 3 Loganathan CLA 2010-05-04 02:35:19 EDT
As new RemoteCommandShellOperation instance becomes usable after reconnection, I set the Importance to Normal.
Comment 4 Martin Oberhuber CLA 2010-05-04 04:27:14 EDT
Changed summary, previous value was:
"
sendCommand(String) method in doesn't invoke handleCommandFinished(String) method in RemoteCommandShellOperation  once the Remote Host is physically disconnected and reconnected
"

My first suspicion here is that physically disconnecting causes the SSH Channel to disconnect. So it's expected that you cannot send/read anything from this channel any more. 

It looks like your RemoteCommandShellOperation would either have to listen to connectionLost events, or would have to check isConnected() before trying to write / read the target.

This theory would also explain why a *new* RemoteCommandShellOperation instance works (it forces a physical reconnect of the SSH channel).

Can you confirm this rough analysis? Do you think you could come up with a patch that satisfies your needs? Or is this something that could be handled in your client code?
Comment 5 Loganathan CLA 2010-05-04 07:13:22 EDT
(In reply to comment #4)
> Changed summary, previous value was:
> "
> sendCommand(String) method in doesn't invoke handleCommandFinished(String)
> method in RemoteCommandShellOperation  once the Remote Host is physically
> disconnected and reconnected
> "
> 
> My first suspicion here is that physically disconnecting causes the SSH Channel
> to disconnect. So it's expected that you cannot send/read anything from this
> channel any more. 
> 
> It looks like your RemoteCommandShellOperation would either have to listen to
> connectionLost events, or would have to check isConnected() before trying to
> write / read the target.
> 
> This theory would also explain why a *new* RemoteCommandShellOperation instance
> works (it forces a physical reconnect of the SSH channel).
> 
> Can you confirm this rough analysis? Do you think you could come up with a
> patch that satisfies your needs? Or is this something that could be handled in
> your client code?

Hi, thanks..

 You are right.. After reconnecting, I found that it doesn't ask for user credentials when I use the same RemoteCommandShellOperation instance; but asks while using a new  RemoteCommandShellOperation instance.

I myself created a wraper on RemoteCommandShellOperation having lifecycle to check connection while using sendCommand() and to create a new RemoteCommandShellOperation instance the if the connection is not active.

But it will be useful to document that RemoteCommandShellOperation instance is not usable  after disconnect/reconnect and to have a wraper to maintain the lifecycle. It will be nice to have that kind of lifecycle class in RSE library itself. Or it will be more nice if the existing RemoteCommandShellOperation instance made to be reused after reconnect.

Thanks..
Comment 6 Martin Oberhuber CLA 2010-05-04 08:00:42 EDT
Since you seem to understand the situation well, and you're able to test this, can you consider contributing a patch?
Comment 7 Loganathan CLA 2010-05-04 08:21:46 EDT
Created attachment 166940 [details]
 The wrapper that is used to send and handle remote commands

This makes use of MyRemoteCommandShellOperation instance to send commands and handle the lifcycle. This might be useful.
Comment 8 Loganathan CLA 2010-05-04 08:23:06 EDT
Created attachment 166941 [details]
The MyRemoteCommandShellOperation which mangages remote commands.

The MyRemoteCommandShellOperation which mangages remote commands.
This waits for command execution and also performs necessary logging of the console output. This might be useful.