apache/druid · error · NoSuchElementException

No items available

Error message

No items available

What it means

QueueNonBlockingPool.take() never blocks: it polls the backing queue and throws NoSuchElementException when the pool is empty, by design rather than waiting for a resource to be returned. This makes exhaustion an immediate, explicit failure for the caller.

Solutions

  1. Ensure every ResourceHolder from take() is closed in a try/finally (or try-with-resources) so objects return to the pool
  2. Increase the pool size or add backpressure/limit concurrency to match pool capacity
  3. Retry with backoff on NoSuchElementException, or use a blocking structure (ArrayBlockingQueue.take) if waiting is acceptable
  4. Check for double-close or early close of the pool itself

Example fix

// before
ResourceHolder<T> holder = pool.take(); // NoSuchElementException under load
use(holder.get());
holder.close();
// after
try (ResourceHolder<T> holder = pool.take()) {
  use(holder.get());
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (pool instanceof QueueNonBlockingPool && sizeKnown && outstanding >= sizeKnown) { /* wait or shed load before take() */ }

Try / catch

try { holder = pool.take(); } catch (NoSuchElementException e) { /* pool exhausted: retry with backoff or shed */ }

Prevention

When it happens

Trigger: Calling take() when all pooled objects are checked out (holders not yet closed) or when the pool was never populated / closed and drained. Any concurrent burst of take() calls exceeding pool size.

Common situations: Resource leaks where holders are not closed in a finally block so objects never return to the pool; pools sized smaller than concurrency; take() after close(); using the pool in a hot path with spikes in demand.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/collections/QueueNonBlockingPool.java:43

/**
 * Implementation of {@link NonBlockingPool} based on a pre-created {@link BlockingQueue} that never actually blocks.
 * If the pool is empty when {@link #take()} is called, it throws {@link NoSuchElementException}.
 */
public class QueueNonBlockingPool<T> implements NonBlockingPool<T>
{
  private final BlockingQueue<T> queue;

  public QueueNonBlockingPool(final BlockingQueue<T> queue)
  {
    this.queue = queue;
  }

  @Override
  public ResourceHolder<T> take()
  {
    final T item = queue.poll();
    if (item == null) {
      throw new NoSuchElementException("No items available");
    }

    return new ReferenceCountingResourceHolder<>(item, () -> queue.add(item));
  }

  /**
   * Number of available items.
   */
  public int availableCount()
  {
    return queue.size();
  }
}

View on GitHub (pinned to 9b90983fd2)