apache/druid · warning

Thread interrupted while taking from queue

Error message

Thread interrupted while taking from queue

What it means

SequenceInputStreamResponseHandler.nextElement pops the next chunk stream from an ArrayBlockingQueue. If the consuming thread is interrupted while blocked on queue.take(), the code logs a warning, re-interrupts the thread, and throws a RuntimeException wrapping the InterruptedException. This typically happens during client-side cancellation of the HTTP response stream.

Solutions

  1. Treat as expected during intentional cancellation; ensure the RuntimeException propagates to unwind the stream loop
  2. Avoid interrupting the HTTP client's consuming thread for non-cancellation reasons (check executor shutdown hooks)
  3. If repeated unexpectedly, audit code that calls Thread.interrupt() or Future.cancel(true) on the reading thread
  4. Ensure the SequenceInputStream is closed promptly on cancellation so the producer side stops adding to the queue

Example fix

// before: cancelling while reading without closing the stream
future.cancel(true); // leaves stream loop interrupted
// after
stream.close(); // drains and stops producer
future.cancel(true);
Defensive patterns

Strategy: try-catch

Validate before calling

// Only iterate the stream while the request is still active
if (responseFuture.isCancelled()) {
  return; // don't start reading
}

Try / catch

try {
  while ((chunk = stream.read()) != -1) { /* consume */ }
} catch (RuntimeException e) {
  if (e.getCause() instanceof InterruptedException) {
    Thread.currentThread().interrupt(); // restore flag, abort reading
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: The thread iterating the SequenceInputStream (from the HTTP response) is interrupted while blocked on queue.take(), e.g. query cancellation, client disconnect handling, or executor shutdown mid-stream.

Common situations: Druid query cancellation via the /druid/v2 cancellation endpoint while the HTTP client is still reading a broker response; server shutdown interrupting worker threads; timeouts that interrupt the consuming thread.

Related errors


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

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/java/util/http/client/response/SequenceInputStreamResponseHandler.java:92

            {
              @Override
              public boolean hasMoreElements()
              {
                // Done is always true until the last stream has be put in the queue.
                // Then the stream should be spouting good InputStreams.
                synchronized (done) {
                  return !done.get() || !queue.isEmpty();
                }
              }

              @Override
              public InputStream nextElement()
              {
                try {
                  return queue.take();
                }
                catch (InterruptedException e) {
                  log.warn(e, "Thread interrupted while taking from queue");
                  Thread.currentThread().interrupt();
                  throw new RuntimeException(e);
                }
              }
            }
        )
    );
  }

  @Override
  public ClientResponse<InputStream> handleChunk(
      ClientResponse<InputStream> clientResponse,
      HttpChunk chunk,
      long chunkNum
  )
  {
    final ChannelBuffer channelBuffer = chunk.getContent();
    final int bytes = channelBuffer.readableBytes();

View on GitHub (pinned to 9b90983fd2)