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

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

Let me summarize the problem:

I want to release resource after timeout occurs. But, after timout occurs, I 
can not check the state of SSHD calls which are  running in background 
asynchronously. There will be always a race condition between SSHD and client 
application.

 
{code:java}
//If timout occurs, session creation will still continue in background 
asynchronously. But, since session variable will be null, it will not be 
possible to release it. I can not use this.
ClientSession session = 
client.connect(...uri...).verify(CONNECT_TIMEOUT).getSession());
{code}
 

 
{code:java}
//I tried to split the operations to handle ConnectFuture separately.
ConnectFuture connectFuture = client.connect(...uri...);
try
  { 
  connectFuture.verify(CONNECT_TIMEOUT); 
  }
   catch (IOException) {
     
   //Although a timeout exception occured, session creation may continue in 
background asynchronously.

  //If connectFuture.isConnected() returns false, it goes into the branch.
  if (!connectFuture.isConnected()) {

     //But, after a while, session creation may be completed in background 
asynchronously. Then, connectFuture.isConnected() will return true, and the 
application may be buggy here.  I can not use this.
     ...
  }
 }
{code}
 

 
{code:java}
//ConnectFuture listener will be notified when session is created or failed. 
But, after timeout, session may not be created or failed yet and there will be 
no notification immediately after timeout. Session creation may be in progress 
asynchronously. So, after timeout, I cannot know the state of session creation.
connectFuture.addListener(...);
{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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to