You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2020/11/17 09:09:37 UTC
[directory-ldap-api] 02/03: Patch for DIRAPI-358
This is an automated email from the ASF dual-hosted git repository.
elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git
commit c037f94331a5f0213e9a321797d390e0f8d89ab2
Author: emmanuel lecharny <em...@busit.com>
AuthorDate: Tue Nov 17 10:09:09 2020 +0100
Patch for DIRAPI-358
---
.../ldap/client/api/LdapNetworkConnection.java | 88 +++++++++++++---------
1 file changed, 53 insertions(+), 35 deletions(-)
diff --git a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
index a3969c8..a7f2f6b 100644
--- a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
+++ b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
@@ -702,6 +702,11 @@ public class LdapNetworkConnection extends AbstractLdapConnection implements Lda
// It may be an exception, or a timeout
Throwable connectionException = connectionFuture.getException();
+ if ( ( connector != null ) && !connector.isDisposing() && !connector.isDisposed() )
+ {
+ connector.dispose();
+ }
+
connector = null;
if ( connectionException == null )
@@ -943,46 +948,59 @@ public class LdapNetworkConnection extends AbstractLdapConnection implements Lda
return true;
}
- // Create the connector if needed
- if ( connector == null )
- {
- createConnector();
- }
-
- // And create the connection future
- ConnectFuture connectionFuture = tryConnect();
-
- // Check if we are good to go
- if ( !connectionFuture.isConnected() )
+ try
{
- // Release the latch
- connectionCloseFuture.cancel( true );
+ // Create the connector if needed
+ if ( connector == null )
+ {
+ createConnector();
+ }
+
+ // And create the connection future
+ ConnectFuture connectionFuture = tryConnect();
+
+ // Check if we are good to go
+ if ( !connectionFuture.isConnected() )
+ {
+ // Release the latch
+ connectionCloseFuture.cancel( true );
+
+ close( connectionFuture );
+ }
+
+ // Check if we are secured if requested
+ if ( config.isUseSsl() )
+ {
+ checkSecured( connectionFuture );
+ }
+
+ // Add a listener to close the session in the session.
+ setCloseListener( connectionFuture );
+
+ // Get back the session
+ ioSession = connectionFuture.getSession();
+
+ // Store the container into the session if we don't have one
+ setBinaryDetector();
+
+ // Initialize the MessageId
+ messageId.set( 0 );
- close( connectionFuture );
+ connectionCloseFuture = new CompletableFuture<>();
+
+ // And return
+ return true;
}
-
- // Check if we are secured if requested
- if ( config.isUseSsl() )
+ catch ( Exception e )
{
- checkSecured( connectionFuture );
- }
-
- // Add a listener to close the session in the session.
- setCloseListener( connectionFuture );
-
- // Get back the session
- ioSession = connectionFuture.getSession();
-
- // Store the container into the session if we don't have one
- setBinaryDetector();
-
- // Initialize the MessageId
- messageId.set( 0 );
-
- connectionCloseFuture = new CompletableFuture<>();
+ if ( ( connector != null ) && !connector.isDisposing() && !connector.isDisposed() )
+ {
+ connector.dispose();
+ connector = null;
+ }
- // And return
- return true;
+ throw e;
+ }
}