{"record":{"id":"43ef33b2df92829f","repo":"apache/druid","slug":"thread-interrupted-while-taking-from-queue","errorCode":null,"errorMessage":"Thread interrupted while taking from queue","messagePattern":"Thread interrupted while taking from queue","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"processing/src/main/java/org/apache/druid/java/util/http/client/response/SequenceInputStreamResponseHandler.java","lineNumber":92,"sourceCode":"            {\n              @Override\n              public boolean hasMoreElements()\n              {\n                // Done is always true until the last stream has be put in the queue.\n                // Then the stream should be spouting good InputStreams.\n                synchronized (done) {\n                  return !done.get() || !queue.isEmpty();\n                }\n              }\n\n              @Override\n              public InputStream nextElement()\n              {\n                try {\n                  return queue.take();\n                }\n                catch (InterruptedException e) {\n                  log.warn(e, \"Thread interrupted while taking from queue\");\n                  Thread.currentThread().interrupt();\n                  throw new RuntimeException(e);\n                }\n              }\n            }\n        )\n    );\n  }\n\n  @Override\n  public ClientResponse<InputStream> handleChunk(\n      ClientResponse<InputStream> clientResponse,\n      HttpChunk chunk,\n      long chunkNum\n  )\n  {\n    final ChannelBuffer channelBuffer = chunk.getContent();\n    final int bytes = channelBuffer.readableBytes();","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/http/client/response/SequenceInputStreamResponseHandler.java#L74-L110","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Treat as expected during intentional cancellation; ensure the RuntimeException propagates to unwind the stream loop","Avoid interrupting the HTTP client's consuming thread for non-cancellation reasons (check executor shutdown hooks)","If repeated unexpectedly, audit code that calls Thread.interrupt() or Future.cancel(true) on the reading thread","Ensure the SequenceInputStream is closed promptly on cancellation so the producer side stops adding to the queue"],"exampleFix":"// before: cancelling while reading without closing the stream\nfuture.cancel(true); // leaves stream loop interrupted\n// after\nstream.close(); // drains and stops producer\nfuture.cancel(true);","handlingStrategy":"try-catch","validationCode":"// Only iterate the stream while the request is still active\nif (responseFuture.isCancelled()) {\n  return; // don't start reading\n}","typeGuard":null,"tryCatchPattern":"try {\n  while ((chunk = stream.read()) != -1) { /* consume */ }\n} catch (RuntimeException e) {\n  if (e.getCause() instanceof InterruptedException) {\n    Thread.currentThread().interrupt(); // restore flag, abort reading\n  } else {\n    throw e;\n  }\n}","preventionTips":["Close the response stream promptly on cancellation so the producer stops filling the queue","Avoid interrupting the HTTP client's reader thread except for real cancellations","Keep consumer throughput ahead of download throughput to avoid queue backpressure","Check executor shutdown hooks that might interrupt in-flight response processing"],"tags":["interrupt","http-client","queue","cancellation"],"backgroundTag":"thread-interrupted","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}