From 1dfff197eadcf24823d7915e6eead2a850f679f9 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Tue, 14 Feb 2012 16:09:28 +0000
Subject: [PATCH] Fix OPENDJ-420: Rare SSLExceptions while handling LDAPS connections and big LDAP searches

---
 opends/src/server/org/opends/server/protocols/ldap/LDAPClientConnection.java |   47 +++++++----------------------------------------
 1 files changed, 7 insertions(+), 40 deletions(-)

diff --git a/opends/src/server/org/opends/server/protocols/ldap/LDAPClientConnection.java b/opends/src/server/org/opends/server/protocols/ldap/LDAPClientConnection.java
index b67cc3a..3af5e14 100644
--- a/opends/src/server/org/opends/server/protocols/ldap/LDAPClientConnection.java
+++ b/opends/src/server/org/opends/server/protocols/ldap/LDAPClientConnection.java
@@ -23,7 +23,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2010-2011 ForgeRock AS.
+ *      Portions Copyright 2010-2012 ForgeRock AS.
  */
 package org.opends.server.protocols.ldap;
 
@@ -360,7 +360,7 @@
 
   private ASN1ByteChannelReader asn1Reader;
 
-  private int APPLICATION_BUFFER_SIZE = 4096;
+  private final int bufferSize;
 
   private final RedirectingByteChannel saslChannel;
   private final RedirectingByteChannel tlsChannel;
@@ -420,7 +420,7 @@
       this.useNanoTime=DirectoryServer.getUseNanoTime();
     }
 
-    APPLICATION_BUFFER_SIZE = connectionHandler.getBufferSize();
+    bufferSize = connectionHandler.getBufferSize();
 
     tlsChannel =
         RedirectingByteChannel.getRedirectingByteChannel(
@@ -428,7 +428,7 @@
     saslChannel =
         RedirectingByteChannel.getRedirectingByteChannel(tlsChannel);
     this.asn1Reader =
-        ASN1.getReader(saslChannel, APPLICATION_BUFFER_SIZE, connectionHandler
+        ASN1.getReader(saslChannel, bufferSize, connectionHandler
             .getMaxRequestSize());
     writeLock = new ReentrantLock();
 
@@ -939,16 +939,8 @@
     {
       if (asn1Writer == null)
       {
-        if (isSecure())
-        {
-          int appBufSize = activeProvider.getAppBufSize();
-          asn1Writer = ASN1.getWriter(saslChannel, writeLock, appBufSize);
-        }
-        else
-        {
-          asn1Writer = ASN1.getWriter(saslChannel, writeLock,
-                  APPLICATION_BUFFER_SIZE);
-        }
+        asn1Writer = ASN1.getWriter(saslChannel, writeLock,
+                  bufferSize);
         asn1WriterMap.put(currentThread, asn1Writer);
       }
 
@@ -2590,9 +2582,6 @@
    */
   public void enableTLS()
   {
-    this.asn1Reader =
-        ASN1.getReader(saslChannel, tlsPendingProvider.getAppBufSize(),
-            connectionHandler.getMaxRequestSize());
     activeProvider = tlsPendingProvider;
     tlsChannel.redirect(tlsPendingProvider);
     tlsPendingProvider = null;
@@ -2608,9 +2597,6 @@
    */
   public void enableSSL(ConnectionSecurityProvider sslProvider)
   {
-    this.asn1Reader =
-        ASN1.getReader(saslChannel, sslProvider.getAppBufSize(),
-            connectionHandler.getMaxRequestSize());
     activeProvider = sslProvider;
     tlsChannel.redirect(sslProvider);
   }
@@ -2624,10 +2610,6 @@
   {
     activeProvider = saslPendingProvider;
     saslChannel.redirect(saslPendingProvider);
-    asn1Reader =
-        ASN1.getReader(saslChannel,
-            saslPendingProvider.getAppBufSize(), connectionHandler
-                .getMaxRequestSize());
     saslPendingProvider = null;
   }
 
@@ -2657,7 +2639,7 @@
    * @return The TLS redirecting byte channel.
    */
    @Override
-   public RedirectingByteChannel getChannel() {
+   public ByteChannel getChannel() {
      return this.tlsChannel;
    }
 
@@ -2678,21 +2660,6 @@
 
 
   /**
-   * Retrieves the application buffer size used in a LDAP client connection.
-   * If a active security provider is being used, then the application buffer
-   * size of that provider is returned.
-   *
-   * @return The application buffer size.
-   */
-  @Override
-  public int getAppBufferSize() {
-    if(activeProvider != null)
-      return activeProvider.getAppBufSize();
-    else
-      return APPLICATION_BUFFER_SIZE;
-  }
-
-  /**
    * {@inheritDoc}
    */
   @Override

--
Gitblit v1.10.0