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

neil_a_wilson
02.47.2007 695efac57879b676d7d6d92d83811558b2dc0d67
Fix a potential deadlock in the task code that could occur if a client tried to
retrieve the task entry at the same time that it was being updated.
2 files modified
61 ■■■■■ changed files
opends/src/server/org/opends/server/backends/task/Task.java 48 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/backends/task/TaskScheduler.java 13 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/backends/task/Task.java
@@ -555,7 +555,14 @@
   */
  void setTaskState(TaskState taskState)
  {
    Lock lock = taskScheduler.writeLockEntry(taskEntryDN);
    // We only need to grab the entry-level lock if we don't already hold the
    // broader scheduler lock.
    boolean needLock = (! taskScheduler.holdsSchedulerLock());
    Lock lock = null;
    if (needLock)
    {
      lock = taskScheduler.writeLockEntry(taskEntryDN);
    }
    try
    {
@@ -579,9 +586,12 @@
    }
    finally
    {
      if (needLock)
      {
      taskScheduler.unlockEntry(taskEntryDN, lock);
    }
  }
  }
@@ -625,7 +635,14 @@
   */
  private void setActualStartTime(long actualStartTime)
  {
    Lock lock = taskScheduler.writeLockEntry(taskEntryDN);
    // We only need to grab the entry-level lock if we don't already hold the
    // broader scheduler lock.
    boolean needLock = (! taskScheduler.holdsSchedulerLock());
    Lock lock = null;
    if (needLock)
    {
      lock = taskScheduler.writeLockEntry(taskEntryDN);
    }
    try
    {
@@ -654,9 +671,12 @@
    }
    finally
    {
      if (needLock)
      {
      taskScheduler.unlockEntry(taskEntryDN, lock);
    }
  }
  }
@@ -685,7 +705,14 @@
   */
  private void setCompletionTime(long completionTime)
  {
    Lock lock = taskScheduler.writeLockEntry(taskEntryDN);
    // We only need to grab the entry-level lock if we don't already hold the
    // broader scheduler lock.
    boolean needLock = (! taskScheduler.holdsSchedulerLock());
    Lock lock = null;
    if (needLock)
    {
      lock = taskScheduler.writeLockEntry(taskEntryDN);
    }
    try
    {
@@ -714,9 +741,12 @@
    }
    finally
    {
      if (needLock)
      {
      taskScheduler.unlockEntry(taskEntryDN, lock);
    }
  }
  }
@@ -879,7 +909,14 @@
  public void addLogMessage(ErrorLogSeverity severity, int messageID,
                            String messageString)
  {
    Lock lock = taskScheduler.writeLockEntry(taskEntryDN);
    // We only need to grab the entry-level lock if we don't already hold the
    // broader scheduler lock.
    boolean needLock = (! taskScheduler.holdsSchedulerLock());
    Lock lock = null;
    if (needLock)
    {
      lock = taskScheduler.writeLockEntry(taskEntryDN);
    }
    try
    {
@@ -935,9 +972,12 @@
    }
    finally
    {
      if (needLock)
      {
      taskScheduler.unlockEntry(taskEntryDN, lock);
    }
  }
  }
opends/src/server/org/opends/server/backends/task/TaskScheduler.java
@@ -1468,6 +1468,19 @@
  /**
   * Indicates whether the current thread already holds a lock on the scheduler.
   *
   * @return  {@code true} if the current thread holds the scheduler lock, or
   *          {@code false} if not.
   */
  boolean holdsSchedulerLock()
  {
    return schedulerLock.isHeldByCurrentThread();
  }
  /**
   * Attempts to acquire a write lock on the specified entry, trying as many
   * times as necessary until the lock has been acquired.
   *