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

matthew_swift
14.51.2008 85472c61f9f6aa066bfbe348ded1c5dd50af012e
Fix issue 2953: ConcurrentModificationException in IdleTimeLimitThread.

Prevent concurrent modifications of the LDAPRequestHandler's Selector key set while accessing it.
1 files modified
24 ■■■■ changed files
opends/src/server/org/opends/server/protocols/ldap/LDAPRequestHandler.java 24 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/protocols/ldap/LDAPRequestHandler.java
@@ -98,6 +98,9 @@
  // The name to use for this request handler.
  private String handlerName;
  // Lock for preventing concurrent updates to the select keys.
  private final Object selectorKeyLock = new Object();
  /**
@@ -303,7 +306,9 @@
        {
          SocketChannel socketChannel = c.getSocketChannel();
          socketChannel.configureBlocking(false);
          socketChannel.register(selector, SelectionKey.OP_READ, c);
          synchronized (selectorKeyLock) {
            socketChannel.register(selector, SelectionKey.OP_READ, c);
          }
        }
        catch (Exception e)
        {
@@ -374,7 +379,11 @@
   */
  public void deregisterClient(LDAPClientConnection clientConnection)
  {
    SelectionKey[] keyArray = selector.keys().toArray(new SelectionKey[0]);
    SelectionKey[] keyArray;
    synchronized (selectorKeyLock) {
      keyArray = selector.keys().toArray(new SelectionKey[0]);
    }
    for (SelectionKey key : keyArray)
    {
      LDAPClientConnection conn = (LDAPClientConnection) key.attachment();
@@ -414,7 +423,11 @@
   */
  public void deregisterAllClients()
  {
    SelectionKey[] keyArray = selector.keys().toArray(new SelectionKey[0]);
    SelectionKey[] keyArray;
    synchronized (selectorKeyLock) {
      keyArray = selector.keys().toArray(new SelectionKey[0]);
    }
    for (SelectionKey key : keyArray)
    {
      try
@@ -454,7 +467,10 @@
   */
  public Collection<LDAPClientConnection> getClientConnections()
  {
    SelectionKey[] keyArray = selector.keys().toArray(new SelectionKey[0]);
    SelectionKey[] keyArray;
    synchronized (selectorKeyLock) {
      keyArray = selector.keys().toArray(new SelectionKey[0]);
    }
    ArrayList<LDAPClientConnection> connList =
         new ArrayList<LDAPClientConnection>(keyArray.length);