[
https://issues.apache.org/jira/browse/SSHD-1085?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17246832#comment-17246832
]
Lyor Goldstein commented on SSHD-1085:
--------------------------------------
I have tried to reproduce and it doesn't - although I am working with version
2.6.0 (soon to be released) I have also tried it with 2.5.1 without any
problems. Here is the code:
{code:java|title=SshClientMain}
Map<String, ?> env = resolveClientEnvironment(client);
PtyChannelConfiguration ptyConfig = resolveClientPtyOptions(client);
ClientChannel channel = channel = session.createExecChannel("sudo
reboot", ptyConfig, env);
try (OutputStream channelOut = new NoCloseOutputStream(System.out);
OutputStream channelErr = new NoCloseOutputStream(System.err)) {
channel.setOut(channelOut);
channel.setErr(channelErr);
channel.open().await(); // TODO use verify and a configurable
timeout
Collection<ClientChannelEvent> result =
channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), 0L);
System.err.println("========= EUREKA: " + result);
} finally {
channel.close();
}
{code}
Simply try running {{SshClientMain}} with the arguments {{-o
StrictHostKeyChecking=no youruser@yourhost sudo reboot}} - mine works like a
charm - I am even getting EXIT_STATUS in the returned result. Therefore you
seem to be doing something wrong - compare your code with mine and remember
that +every step is important+, so if you are doing something else then
something is probably wrong with your code.
In any case, try also the code in
https://github.com/lgoldstein/mina-sshd/tree/SSHD-1085 - it speeds up the
detection that channel is closed.
> channel.waitFor() get stuck when run reboot command
> ---------------------------------------------------
>
> Key: SSHD-1085
> URL: https://issues.apache.org/jira/browse/SSHD-1085
> Project: MINA SSHD
> Issue Type: Bug
> Affects Versions: 2.5.1
> Environment: linux
> Reporter: min yun law
> Priority: Major
>
> Trying to run linux command "reboot" by mina sshd to remote node, the node is
> in reboot, but the ClientChannel object still keep open, not in closed
> status, Here is the logic code in my project:
>
> {code:java}
> String command = "reboot";
> ChannelExec channel = clientSession.createExecChannel(command);
> if(!channel.isClosed())
> {
> ByteArrayOutputStream out = new ByteArrayOutputStream();
> ByteArrayOutputStream err = new ByteArrayOutputStream(); channel.setOut(out);
> channel.setErr(err);
> channel.open().await(); //this passed
> //follow call will cause stuck
> Collection<ClientChannelEvent> waitMask =
> channel.waitFor(REMOTE_COMMAND_WAIT_EVENTS, 0L);
> String outputStr = new String(out.toByteArray(), StandardCharsets.UTF_8);
> //some case this will throw runtime exception
> int exitStatus = channel.getExitStatus();
> }
>
> {code}
>
> So why the ChannelExec cannot get the correct channel status when remote node
> is rebooting?
>
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]