From bf7e97e3cb610d18d4fbe62e614cdb55c2d24930 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Fri, 17 Sep 2010 22:16:30 +0000
Subject: [PATCH] Fix potential deadlock which may occur while performing simultaneous large searches and modify operations on the same connection. Use single channel lock per connection and share it across thread local ASN1 writers.

---
 opends/src/server/org/opends/server/protocols/asn1/ASN1.java |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/opends/src/server/org/opends/server/protocols/asn1/ASN1.java b/opends/src/server/org/opends/server/protocols/asn1/ASN1.java
index b74a685..89f977e 100644
--- a/opends/src/server/org/opends/server/protocols/asn1/ASN1.java
+++ b/opends/src/server/org/opends/server/protocols/asn1/ASN1.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2008 Sun Microsystems, Inc.
+ *      Copyright 2006-2010 Sun Microsystems, Inc.
  */
 package org.opends.server.protocols.asn1;
 
@@ -32,6 +32,7 @@
 import java.io.OutputStream;
 import java.nio.channels.ReadableByteChannel;
 import java.nio.channels.WritableByteChannel;
+import java.util.concurrent.locks.ReentrantLock;
 
 import org.opends.server.types.ByteSequence;
 import org.opends.server.types.ByteString;
@@ -263,11 +264,14 @@
    *
    * @param channel
    *          The writable byte channel.
+   * @param writeLock
+   *          The write lock to use when flushing to the destination.
    * @return The new ASN.1 writer.
    */
-  public static ASN1Writer getWriter(WritableByteChannel channel)
+  public static ASN1Writer getWriter(WritableByteChannel channel,
+                                     ReentrantLock writeLock)
   {
-    return new ASN1ByteChannelWriter(channel, 4096);
+    return new ASN1ByteChannelWriter(channel, writeLock, 4096);
   }
 
 
@@ -282,14 +286,17 @@
    *
    * @param channel
    *          The writable byte channel.
+   * @param writeLock
+   *          The write lock to use when flushing to the destination.
    * @param bufferSize
    *          The buffer size to use when writing to the channel.
    * @return The new ASN.1 writer.
    */
   public static ASN1Writer getWriter(WritableByteChannel channel,
+                                     ReentrantLock writeLock,
                                      int bufferSize)
   {
-    return new ASN1ByteChannelWriter(channel, bufferSize);
+    return new ASN1ByteChannelWriter(channel, writeLock, bufferSize);
   }
 
 

--
Gitblit v1.10.0