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

dgü commented on SSHD-1278:
---------------------------

If I'm not wrong, this can be a workaround if _AuthFuture#cancel()_ is 
synchronous.

 
{code:java}
AuthFuture authFuture = clientSession.auth();
try
  { 
  authFuture.verify(CONNECT_TIMEOUT); 
  }
   catch (IOException e) {
    
    //Assuming authFuture.cancel() is synchronous. This will cancel 
authentication attempt only if authentication is not completed yet.
    authFuture.cancel();

    //authFuture is now authenticated or canceled. It can not be running in 
background asynchronously. So, it's safe to check its status by 
authFuture.isCanceled(). If authentication is completed, ignore the exception. 
Otherwise throw the exception.
    if (authFuture.isCanceled()) {
      throw e;
    }
}
{code}

> How to release client connection resources after connection timeout occurs ?
> ----------------------------------------------------------------------------
>
>                 Key: SSHD-1278
>                 URL: https://issues.apache.org/jira/browse/SSHD-1278
>             Project: MINA SSHD
>          Issue Type: Question
>    Affects Versions: 2.8.0
>         Environment: Java SE 8, NetBeans IDE 8.2
>            Reporter: dgü
>            Assignee: Lyor Goldstein
>            Priority: Major
>
> Hello!
> I want to release client connection resources after connection timeout occurs 
> ?
> This is the code:
> {code:java}
> ConnectFuture connectFuture = sshClient.connect(uri.toString());
> try {
>     //connectFuture.isConnected() returns false
>     connectFuture.verify(timeout);
> } catch (IOException e) {
>     //connectFuture.isConnected() returns true
>     connectFuture.cancel();
>     //connectFuture.isCanceled() returns false
>     //connectFuture.isConnected() returns true
>     throw e;
> }
> {code}
> I guess there is a race condition between client connection and 
> {{ConnectFuture#isConnected()}}. 
> For example, this code may be wrong:
> {code:java}
> if (!connectFuture.isConnected()) {
>   //connectFuture.isConnected() may return true
> }
> {code}
> In my case, session is connected after timeout. 
> How can I be sure that client is still not connected and release its 
> resources after connection timeout occurs ?
> Thanks in advance!



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org
For additional commands, e-mail: dev-h...@mina.apache.org

Reply via email to