mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Matthew Swift
24.03.2015 b93b0473f89d640296c64c36d3477689bd6a29b8
OPENDJ-1607 Cancel connection timeout future on completion

Failure to cancel the future prevents the scheduled executor from
shutting down quickly. Also forcefully shutdown the scheduler rather
than waiting for any remaining tasks to complete, since they should no
longer be needed.
2 files modified
19 ■■■■■ changed files
opendj-sdk/opendj-core/src/main/java/com/forgerock/opendj/util/StaticUtils.java 8 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/LDAPConnectionFactory.java 11 ●●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/com/forgerock/opendj/util/StaticUtils.java
@@ -41,7 +41,6 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import org.forgerock.i18n.LocalizableException;
import org.forgerock.i18n.LocalizableMessage;
@@ -119,12 +118,7 @@
                @Override
                protected void destroyInstance(ScheduledExecutorService instance) {
                    instance.shutdown();
                    try {
                        instance.awaitTermination(5, TimeUnit.SECONDS);
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                    }
                    instance.shutdownNow();
                }
            };
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/LDAPConnectionFactory.java
@@ -453,8 +453,9 @@
        // Register the connect timeout timer.
        final PromiseImpl<Connection, LdapException> promise = PromiseImpl.create();
        final AtomicReference<LDAPConnectionImpl> connectionHolder = new AtomicReference<>();
        final ScheduledFuture<?> timeoutFuture;
        if (connectTimeoutMS > 0) {
            scheduler.get().schedule(new Runnable() {
            timeoutFuture = scheduler.get().schedule(new Runnable() {
                @Override
                public void run() {
                    if (promise.tryHandleException(newConnectTimeoutError())) {
@@ -463,6 +464,8 @@
                    }
                }
            }, connectTimeoutMS, TimeUnit.MILLISECONDS);
        } else {
            timeoutFuture = null;
        }
        // Now connect, negotiate SSL, etc.
@@ -482,6 +485,9 @@
            .thenOnResult(new ResultHandler<Result>() {
                @Override
                public void handleResult(Result result) {
                    if (timeoutFuture != null) {
                        timeoutFuture.cancel(false);
                    }
                    final LDAPConnectionImpl connection = connectionHolder.get();
                    final ConnectionImpl connectionImpl = new ConnectionImpl(connection);
                    if (!promise.tryHandleResult(registerConnection(connectionImpl))) {
@@ -492,6 +498,9 @@
            .thenOnException(new ExceptionHandler<LdapException>() {
                @Override
                public void handleException(final LdapException e) {
                    if (timeoutFuture != null) {
                        timeoutFuture.cancel(false);
                    }
                    final LdapException connectException;
                    if (e instanceof ConnectionException || e instanceof AuthenticationException) {
                        connectException = e;