[
https://issues.apache.org/jira/browse/SSHD-1223?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17441930#comment-17441930
]
Thomas Wolf commented on SSHD-1223:
-----------------------------------
Experimenting a little with this test: I think the test and that in this test
an exception gets raised is OK. Just the comment is wrong.
I don't see any a race at all, and getting an exception in this case is the
correct behavior. One probably does not want
{{future.verify(CONNECT_TIMEOUT).getSession()}} to succeed and yield a closed
session -- users should not have to check whether the session is closed after
having just gotten it. So an exception seems better. Unfortunately the cause of
this {{MissingAttachedSessionException}} is only reported in the logs; it isn't
attached to the future that {{verify()}} waits on.
Without further input on the actual problem that some of your sessions get this
exception (kind of server connected to, debug logs) I don't see what we could
do here.
> MissingAttachedSessionException when starting concurrent SshClient connections
> ------------------------------------------------------------------------------
>
> Key: SSHD-1223
> URL: https://issues.apache.org/jira/browse/SSHD-1223
> Project: MINA SSHD
> Issue Type: Bug
> Affects Versions: 2.7.0
> Environment: sshd 2.7.0
> Spring boot 2.5.4
> Java 11
> Reporter: Steve Jankowski
> Priority: Major
>
> When 10+ ssh clients are connecting concurrently, some of them fail with
> MissingAttachedSessionException
>
> {noformat}
> org.apache.sshd.common.session.helpers.MissingAttachedSessionException: No
> session attached to Nio2Session[local=/172.31.20.24:48754,
> remote=/172.31.20.9:22]
> at
> org.apache.sshd.common.session.helpers.AbstractSession.getSession(AbstractSession.java:2443)
> at
> org.apache.sshd.common.session.helpers.AbstractSession.getSession(AbstractSession.java:2408)
> at
> org.apache.sshd.client.SshClient.onConnectOperationComplete(SshClient.java:739)
> at
> org.apache.sshd.client.SshClient$1.operationComplete(SshClient.java:716)
> at
> org.apache.sshd.client.SshClient$1.operationComplete(SshClient.java:697)
> at
> org.apache.sshd.common.future.AbstractSshFuture.notifyListener(AbstractSshFuture.java:159)
> at
> org.apache.sshd.common.future.DefaultSshFuture.notifyListeners(DefaultSshFuture.java:209)
> at
> org.apache.sshd.common.future.DefaultSshFuture.setValue(DefaultSshFuture.java:112)
> at
> org.apache.sshd.common.io.nio2.Nio2Connector$DefaultIoConnectFuture.setSession(Nio2Connector.java:233)
> at
> org.apache.sshd.common.io.nio2.Nio2Connector$ConnectionCompletionHandler.onCompleted(Nio2Connector.java:154)
> at
> org.apache.sshd.common.io.nio2.Nio2Connector$ConnectionCompletionHandler.onCompleted(Nio2Connector.java:116)
> at
> org.apache.sshd.common.io.nio2.Nio2CompletionHandler.lambda$completed$0(Nio2CompletionHandler.java:38)
> at java.base/java.security.AccessController.doPrivileged(Native Method)
> at
> org.apache.sshd.common.io.nio2.Nio2CompletionHandler.completed(Nio2CompletionHandler.java:37)
> at java.base/sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:127)
> at java.base/sun.nio.ch.Invoker$2.run(Invoker.java:219)
> at
> java.base/sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112)
> at
> java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
> at
> java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
> at java.base/java.lang.Thread.run(Thread.java:829) {noformat}
>
> My code is roughly:
>
> {noformat}
> SshClient ssh = SshClient.setUpDefaultClient();
> ssh.start();
> // loop this 10 ish times
> {
> ConnectFuture future;
> try {
> future = ssh.connect(SSH_USER, ip, SSH_PORT);
> future.addListener(new
> SshFutureListener<ConnectFuture>() {
> @Override
> public void operationComplete(ConnectFuture
> future) {
> if (future.getException() != null) {
> logger.error("connect failure",
> future.getException());
> }
> }
> });
> } catch (IOException ex) {
> logger.error("startCommand",ex);
> return;
> }
> }
> {noformat}
> Some of the ssh connections fail. The ConnectFuture listener gets
> MissingAttachedSessionException
> This test case is highly suspicious: ClientDeadlockTest
> {noformat}
> @Test
> public void testSimpleClient() throws Exception {
> client.start();
> ConnectFuture future = client.connect(getCurrentTestName(),
> TEST_LOCALHOST, port);
> try (ClientSession session =
> future.verify(CONNECT_TIMEOUT).getSession()) {
> Collection<ClientSessionEvent> events
> =
> session.waitFor(EnumSet.of(ClientSession.ClientSessionEvent.CLOSED),
> TimeUnit.SECONDS.toMillis(7L));
> assertTrue("Close event not signalled: " + events,
> events.contains(ClientSession.ClientSessionEvent.CLOSED));
> assertFalse("Session not marked as closed", session.isOpen());
> } catch (SshException e) {
> Throwable cause = e.getCause();
> // Due to a race condition we might get this exception
> if (!(cause instanceof MissingAttachedSessionException)) {
> throw e;
> }
> }
> }
> {noformat}
> The test case explicitly calls out a race condition, and ignores the
> exception.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]