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

Matthew Swift
13.57.2012 26244e02e37b338851b63693dd72f782a5a1b555
Fix OPENDJ-612: SDK: Race conditions installing client/server filter chains during connect/bind/accept

Use new TCPNIOConnectorHandler and TCPNIOBindingHandler APIs for connecting and listening instead of the transport.
5 files modified
28 ■■■■ changed files
opendj3/opendj-ldap-sdk/pom.xml 5 ●●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnectionFactoryImpl.java 8 ●●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPListenerImpl.java 7 ●●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPListenerTestCase.java 6 ●●●● patch | view | raw | blame | history
opendj3/pom.xml 2 ●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/pom.xml
@@ -88,11 +88,6 @@
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <excludes>
            <exclude>**/ConnectionFactoryTestCase.java</exclude>
          </excludes>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnectionFactoryImpl.java
@@ -47,9 +47,11 @@
import org.forgerock.opendj.ldap.responses.ExtendedResult;
import org.glassfish.grizzly.CompletionHandler;
import org.glassfish.grizzly.EmptyCompletionHandler;
import org.glassfish.grizzly.SocketConnectorHandler;
import org.glassfish.grizzly.filterchain.FilterChain;
import org.glassfish.grizzly.filterchain.FilterChainBuilder;
import org.glassfish.grizzly.filterchain.TransportFilter;
import org.glassfish.grizzly.nio.transport.TCPNIOConnectorHandler;
import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
import com.forgerock.opendj.util.AsynchronousFutureResult;
@@ -148,8 +150,6 @@
            // Test shows that its much faster with non block writes but risk
            // running out of memory if the server is slow.
            connection.configureBlocking(true);
            connection.setProcessor(defaultFilterChain);
            final LDAPConnection ldapConnection = new LDAPConnection(connection, options);
            clientFilter.registerConnection(connection, ldapConnection);
            return ldapConnection;
@@ -231,10 +231,12 @@
    @Override
    public FutureResult<Connection> getConnectionAsync(
            final ResultHandler<? super Connection> handler) {
        final SocketConnectorHandler connectorHandler =
                TCPNIOConnectorHandler.builder(transport).processor(defaultFilterChain).build();
        final AsynchronousFutureResult<Connection> future =
                new AsynchronousFutureResult<Connection>(handler);
        final CompletionHandlerAdapter cha = new CompletionHandlerAdapter(future);
        transport.connect(socketAddress, cha);
        connectorHandler.connect(socketAddress, cha);
        return future;
    }
opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPListenerImpl.java
@@ -39,6 +39,7 @@
import org.glassfish.grizzly.filterchain.FilterChain;
import org.glassfish.grizzly.filterchain.FilterChainBuilder;
import org.glassfish.grizzly.filterchain.TransportFilter;
import org.glassfish.grizzly.nio.transport.TCPNIOBindingHandler;
import org.glassfish.grizzly.nio.transport.TCPNIOServerConnection;
import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
@@ -83,9 +84,9 @@
                FilterChainBuilder.stateless().add(new TransportFilter()).add(
                        new LDAPServerFilter(this, new LDAPReader(decodeOptions), options
                                .getMaxRequestSize())).build();
        this.serverConnection = transport.bind(address, options.getBacklog());
        this.serverConnection.setProcessor(defaultFilterChain);
        final TCPNIOBindingHandler bindingHandler =
                TCPNIOBindingHandler.builder(transport).processor(defaultFilterChain).build();
        this.serverConnection = bindingHandler.bind(address, options.getBacklog());
    }
    /**
opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPListenerTestCase.java
@@ -247,7 +247,7 @@
                new MockServerConnectionFactory(serverConnection);
        final LDAPListener listener =
                new LDAPListener("localhost", TestCaseUtils.findFreePort(),
                        serverConnectionFactory/*, options*/);
                        serverConnectionFactory);
        try {
            // Connect and close.
            final Connection connection =
@@ -346,7 +346,7 @@
     * @throws Exception
     *             If an unexpected exception occurred.
     */
    @Test(enabled = false)
    @Test
    public void testLDAPListenerLoadBalanceDuringHandleBind() throws Exception {
        // Online server listener.
        final int onlineServerPort = TestCaseUtils.findFreePort();
@@ -525,7 +525,7 @@
     * @throws Exception
     *             If an unexpected exception occurred.
     */
    @Test(enabled = false)
    @Test
    public void testLDAPListenerProxyDuringHandleBind() throws Exception {
        final MockServerConnection onlineServerConnection = new MockServerConnection();
        final MockServerConnectionFactory onlineServerConnectionFactory =
opendj3/pom.xml
@@ -108,7 +108,7 @@
    <docTargetVersion>2.5.0</docTargetVersion>
    <siteDistributionURL>scp://forgerock.org/var/www/vhosts/opendj.forgerock.org/httpdocs</siteDistributionURL>
    <i18nFrameworkVersion>1.4.0</i18nFrameworkVersion>
    <grizzlyFrameworkVersion>2.2.18</grizzlyFrameworkVersion>
    <grizzlyFrameworkVersion>2.2.19-SNAPSHOT</grizzlyFrameworkVersion>
    <gaId>UA-23412190-8</gaId>
    <!--
      Release date is specified only when building the documentation