host.isOffline() returns false even when the (SSH) host is disconnected
Bugzilla Link | 417218 |
Status | NEW |
Importance | P3 normal |
Reported | Sep 13, 2013 14:59 EDT |
Modified | Sep 13, 2013 15:00 EDT |
Version | 3.4 |
Reporter | Samuel Lampa |
Description
I have some code that checks whether I'm currently logged in to a remote SSH connection with a certain name, that I set in a preferences page. The code looks like this:
public boolean isLoggedIn() {\
IHost host = getHPCHost();\
if (host.isOffline()) {\
return false;\
} else {\
return true;\
}\
}
public IHost getHPCHost() {\
IHost hpcHost = null;\
ISystemRegistry reg = SystemStartHere.getSystemRegistry();\
IHost[] hosts = reg.getHosts();\
if (hosts.length == 0) {\
log.error("No host names found!");\
}\
\
for (IHost host : hosts) {\
String hostAlias = host.getAliasName();\
String hostNameInPrefPage = Activator.getDefault().getPreferenceStore().getString("hostname");\
if (hostAlias.equals(hostNameInPrefPage)) {\
hpcHost = host;\
break;\
}\
}\
return hpcHost;\
}
... so I execute isLoggedIn() to see if I'm logged in or not.
The problem is that isLoggedIn() will return true even if I'm not logged in. That is, host.isOffline() returns false, even if I haven't logged in.
Steps to reproduce:
-
Create a remote SSH connection with the hostname [hostname].
-
Add the following code somewhere:
public boolean isLoggedIn() {
IHost host = getHPCHost();
if (host.isOffline()) {
log.error
} else {
return true;
}
}public IHost getHPCHost() {
ISystemRegistry reg = SystemStartHere.getSystemRegistry();
IHost[] hosts = reg.getHosts();
if (hosts.length == 0) {
log.error("No host names found!");
}
for (IHost host : hosts) {
String hostAlias = host.getAliasName();
if (hostAlias.equals([hostname])) {
return host;
}
}
return null;
} -
Add some code that execute isLoggedIn()
-
Set a breakpoint inside isLoggedIn()
-
Start your test application in the debugger
-
Make sure the connection you are connecting to is offline (right click on it and choose "Disconnect")
-
Make sure that the isLoggedIn() code is run
-
Watch the output of the host.isOffline() function
(For me, it incorrectly returns false)