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

Matthew Swift
25.23.2012 d6300a5ca611c059121fdaf0c54acd99772d48cc
Fix OPENDJ-627: ConnectionPool internal state becomes invalid when stale connections are discarded

Release the semaphore when a stale connection is encountered.
2 files modified
20 ■■■■ changed files
opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/FixedConnectionPool.java 18 ●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/ConnectionPoolTestCase.java 2 ●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/FixedConnectionPool.java
@@ -233,12 +233,9 @@
                // The connection may have been disconnected by the remote
                // server, but the server may still be available. In order to
                // avoid leaving pending futures hanging indefinitely, we should
                // try to reconnect immediately.
                // Close the dead connection.
                // try to reconnect immediately. No need to release/acquire
                // currentPoolSize.
                connection.close();
                // Try to get a new connection to replace it.
                factory.getConnectionAsync(connectionResultHandler);
                if (DEBUG_LOG.isLoggable(Level.FINE)) {
@@ -543,11 +540,7 @@
        @SuppressWarnings("unchecked")
        AsynchronousFutureResult<Connection> getWaitingFuture() {
            if (value instanceof AsynchronousFutureResult) {
                return (AsynchronousFutureResult<Connection>) value;
            } else {
                throw new IllegalStateException();
            }
        }
        boolean isWaitingFuture() {
@@ -656,6 +649,13 @@
                } else {
                    // Close the stale connection and try again.
                    connection.close();
                    currentPoolSize.release();
                    if (DEBUG_LOG.isLoggable(Level.FINE)) {
                        DEBUG_LOG.fine(String.format("Connection no longer valid. "
                                + "currentPoolSize=%d, poolSize=%d", poolSize
                                - currentPoolSize.availablePermits(), poolSize));
                    }
                }
            } else {
                // Grow the pool if needed.
opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/ConnectionPoolTestCase.java
@@ -373,7 +373,7 @@
     * @throws Exception
     *             If an unexpected error occurred.
     */
    @Test(enabled = false)
    @Test
    public void testSkipStaleConnectionsOnGetWhenAtCapacity() throws Exception {
        // Setup.
        final Connection connection1 = mock(Connection.class);