[ 
https://issues.apache.org/jira/browse/KARAF-3649?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14732473#comment-14732473
 ] 

Jan-Peter Nilsson commented on KARAF-3649:
------------------------------------------

The problem is with getInstanceState(name) in AdminServiceImpl.java (or 
InstanceServiceImpl.java for 3.0/4.0), to check if the instance is up it uses a 
plain socket to connect to it and then immediately closes the connection.
When the instance gets the connection it will try to do a key exchange with the 
client, as the client closes the socket this fails resulting in the above log 
messages.

I think the easiest fix would be to use SshClient instead of Socket, so that it 
can play along with the instance letting it do the key exchange before closing 
the connection.

That is, replacing
{code:java}
try {
    Socket s = new Socket(host, port);
    s.close();
    return Instance.STARTED;
} catch (Exception e) {
    // ignore
}
{code}

with something like

{code:java}
SshClient client = SshClient.setUpDefaultClient();
client.start();
try {
    client.connect("karaf", host, port).await().cancel()
    return Instance.STARTED;
} catch (Exception e) {
    // ignore
} finally {
    client.stop();
}
{code}

As a workaround the log level for 
log4j.logger.org.apache.sshd.common.io.nio2.Nio2Session can be adjusted, but 
that will of course also affect other messages from the same component.

> "instance:list" causes IllegalStateException: No session available
> ------------------------------------------------------------------
>
>                 Key: KARAF-3649
>                 URL: https://issues.apache.org/jira/browse/KARAF-3649
>             Project: Karaf
>          Issue Type: Bug
>    Affects Versions: 3.0.3
>            Reporter: Martin Lichtin
>            Assignee: Jean-Baptiste Onofré
>            Priority: Minor
>
> Just executing "instance:list" causes following exception:
> {noformat}
> 2015-04-08 10:14:58,860 | INFO  | 4]-nio2-thread-8 | ServerSession            
>         | 28 - org.apache.sshd.core - 0.12.0 | Server session created from 
> /127.0.0.1:58539
> 2015-04-08 10:14:58,864 | INFO  | 4]-nio2-thread-8 | Nio2Session              
>         | 28 - org.apache.sshd.core - 0.12.0 | Exception handler threw 
> exception, closing the session
> java.lang.IllegalStateException: No session available
>         at 
> org.apache.sshd.common.AbstractSessionIoHandler.exceptionCaught(AbstractSessionIoHandler.java:49)[28:org.apache.sshd.core:0.12.0]
>         at 
> org.apache.sshd.common.io.nio2.Nio2Session.exceptionCaught(Nio2Session.java:126)[28:org.apache.sshd.core:0.12.0]
>         at 
> org.apache.sshd.common.io.nio2.Nio2Session.access$500(Nio2Session.java:47)[28:org.apache.sshd.core:0.12.0]
>         at 
> org.apache.sshd.common.io.nio2.Nio2Session$2.onFailed(Nio2Session.java:230)
>         at 
> org.apache.sshd.common.io.nio2.Nio2CompletionHandler$2.run(Nio2CompletionHandler.java:41)
>         at java.security.AccessController.doPrivileged(Native 
> Method)[:1.8.0_25]
>         at 
> org.apache.sshd.common.io.nio2.Nio2CompletionHandler.failed(Nio2CompletionHandler.java:39)[28:org.apache.sshd.core:0.12.0]
>         at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:128)[:1.8.0_25]
>         at sun.nio.ch.Invoker.invokeDirect(Invoker.java:157)[:1.8.0_25]
>         at 
> sun.nio.ch.UnixAsynchronousSocketChannelImpl.implWrite(UnixAsynchronousSocketChannelImpl.java:736)[:1.8.0_25]
>         at 
> sun.nio.ch.AsynchronousSocketChannelImpl.write(AsynchronousSocketChannelImpl.java:382)[:1.8.0_25]
>         at 
> sun.nio.ch.AsynchronousSocketChannelImpl.write(AsynchronousSocketChannelImpl.java:399)[:1.8.0_25]
>         at 
> java.nio.channels.AsynchronousSocketChannel.write(AsynchronousSocketChannel.java:577)[:1.8.0_25]
>         at 
> org.apache.sshd.common.io.nio2.Nio2Session.startWriting(Nio2Session.java:212)[28:org.apache.sshd.core:0.12.0]
>         at 
> org.apache.sshd.common.io.nio2.Nio2Session.write(Nio2Session.java:115)[28:org.apache.sshd.core:0.12.0]
>         at 
> org.apache.sshd.common.session.AbstractSession.doWritePacket(AbstractSession.java:508)[28:org.apache.sshd.core:0.12.0]
>         at 
> org.apache.sshd.common.session.AbstractSession.writePacket(AbstractSession.java:495)[28:org.apache.sshd.core:0.12.0]
>         at 
> org.apache.sshd.common.session.AbstractSession.sendKexInit(AbstractSession.java:856)[28:org.apache.sshd.core:0.12.0]
>         at 
> org.apache.sshd.server.session.ServerSession.sendKexInit(ServerSession.java:128)[28:org.apache.sshd.core:0.12.0]
>         at 
> org.apache.sshd.server.session.ServerSession.<init>(ServerSession.java:60)[28:org.apache.sshd.core:0.12.0]
>         at 
> org.apache.sshd.server.session.SessionFactory.doCreateSession(SessionFactory.java:43)[28:org.apache.sshd.core:0.12.0]
>         at 
> org.apache.sshd.common.session.AbstractSessionFactory.createSession(AbstractSessionFactory.java:38)[28:org.apache.sshd.core:0.12.0]
>         at 
> org.apache.sshd.common.AbstractSessionIoHandler.sessionCreated(AbstractSessionIoHandler.java:36)[28:org.apache.sshd.core:0.12.0]
>         at 
> org.apache.sshd.common.io.nio2.Nio2Acceptor$AcceptCompletionHandler.onCompleted(Nio2Acceptor.java:127)[28:org.apache.sshd.core:0.12.0]
>         at 
> org.apache.sshd.common.io.nio2.Nio2Acceptor$AcceptCompletionHandler.onCompleted(Nio2Acceptor.java:108)[28:org.apache.sshd.core:0.12.0]
>         at 
> org.apache.sshd.common.io.nio2.Nio2CompletionHandler$1.run(Nio2CompletionHandler.java:32)
>         at java.security.AccessController.doPrivileged(Native 
> Method)[:1.8.0_25]
>         at 
> org.apache.sshd.common.io.nio2.Nio2CompletionHandler.completed(Nio2CompletionHandler.java:30)[28:org.apache.sshd.core:0.12.0]
>         at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:126)[:1.8.0_25]
>         at sun.nio.ch.Invoker$2.run(Invoker.java:218)[:1.8.0_25]
>         at 
> sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112)[:1.8.0_25]
>         at 
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_25]
>         at 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_25]
>         at java.lang.Thread.run(Thread.java:745)[:1.8.0_25]
> Caused by: java.io.IOException: Broken pipe
>         at sun.nio.ch.FileDispatcherImpl.write0(Native Method)[:1.8.0_25]
>         at 
> sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47)[:1.8.0_25]
>         at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)[:1.8.0_25]
>         at sun.nio.ch.IOUtil.write(IOUtil.java:65)[:1.8.0_25]
>         at 
> sun.nio.ch.UnixAsynchronousSocketChannelImpl.implWrite(UnixAsynchronousSocketChannelImpl.java:691)[:1.8.0_25]
>         ... 24 more
> {noformat}
> No instance needs to be created to provoke this.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to