apache/druid · warning · RejectedExecutionException

Got Interrupted while adding to the Queue

Error message

Got Interrupted while adding to the Queue

What it means

The same custom RejectedExecutionHandler in Execs attempts executor.getQueue().put(r) when the executor is running; if the inserting thread is interrupted while blocked on a full queue, it wraps the InterruptedException in RejectedExecutionException('Got Interrupted while adding to the Queue'). The original interrupt status is carried as the cause.

Solutions

  1. Increase the executor's queue capacity or add more worker threads so put() rarely blocks
  2. Restore the interrupt status in your caller (Thread.currentThread().interrupt()) if you catch and swallow this exception upstream
  3. Check whether the submitting thread is being interrupted too aggressively (over-eager cancellation/timeouts)
  4. Use offer() with timeout or CallerRunsPolicy-style backpressure instead of indefinite blocking put

Example fix

// before
exec.submit(task); // may throw RejectedExecutionException(cause=InterruptedException)
// after
try {
  exec.submit(task);
} catch (RejectedExecutionException e) {
  if (e.getCause() instanceof InterruptedException) {
    Thread.currentThread().interrupt();
  }
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// avoid blocking put on a full queue
boolean accepted = executor.getQueue().offer(task);
if (!accepted) { /* apply backpressure or reject explicitly */ }

Try / catch

try {
  executor.submit(task);
} catch (RejectedExecutionException e) {
  if (e.getCause() instanceof InterruptedException) {
    Thread.currentThread().interrupt(); // preserve interrupt status
  }
  throw e;
}

Prevention

When it happens

Trigger: Submitting a task to a bounded ThreadPoolExecutor whose queue is full, where the calling thread is interrupted while blocked in put() waiting for queue space.

Common situations: Overloaded executors with small bounded queues and fast producers; task-submitter threads cancelled/interrupted during shutdown or timeout; caller thread's interrupt flag set by an enclosing timeout mechanism.

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/47b6a2e829ed104b. Report an issue: GitHub.

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/java/util/common/concurrent/Execs.java:169

        nThreads,
        nThreads,
        0L,
        TimeUnit.MILLISECONDS,
        queue,
        makeThreadFactory(nameFormat, priority),
        new RejectedExecutionHandler()
        {
          @Override
          public void rejectedExecution(Runnable r, ThreadPoolExecutor executor)
          {
            if (executor.isShutdown()) {
              throw new RejectedExecutionException("Executor is shutdown, rejecting task");
            }
            try {
              executor.getQueue().put(r);
            }
            catch (InterruptedException e) {
              throw new RejectedExecutionException("Got Interrupted while adding to the Queue", e);
            }
          }
        }
    );
  }

  public static ListeningExecutorService directExecutor()
  {
    return new DirectExecutorService();
  }
}

View on GitHub (pinned to 9b90983fd2)