Uploaded image for project: 'Blazegraph (by SYSTAP)'
  1. Blazegraph (by SYSTAP)
  2. BLZG-1954

Potential Race Condition in Latched Executor

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Done
    • Priority: Medium
    • Resolution: Done
    • Affects Version/s: BLAZEGRAPH_2_1_1
    • Fix Version/s: BLAZEGRAPH_2_1_2
    • Component/s: Other
    • Labels:
      None

      Description

      There is a potential race condition in LatchedExecutor, which I suspect is the cause of the issue.

      T1 has permit on semaphore.
      T2 has called execute(task).

      T1: queue.poll() – returns null
      T2: queue.offer(task)
      T2: semaphore.tryAcquire() – fails since T2 has permit
      T1: semaphore.release()

      If the execution is interleaved in that order, the new work availability will be missed and the LatchedExecutor will fail to execute the pending task.

      The following code reproduces the issue:

      import com.bigdata.util.concurrent.LatchedExecutor;
      import java.util.concurrent.*;
      public class LatchedExecutorTest {
          public static void main(String[] args) throws Exception {
              LatchedExecutor latched = new LatchedExecutor(Executors.newCachedThreadPool(), 1);
              final Semaphore sem = new Semaphore(1);
              Runnable task = new Runnable() {
                  @Override
                  public void run() {
                      sem.release();
                  }
              };
       
              int iter = 0;
              while (true) {
                  System.err.println("iter=" + iter++);
                  sem.acquire();
                  latched.execute(task);
              }
          }
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              martyncutcher martyncutcher
              Reporter:
              beebs Brad Bebee
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: