{"record":{"id":"47b6a2e829ed104b","repo":"apache/druid","slug":"got-interrupted-while-adding-to-the-queue","errorCode":null,"errorMessage":"Got Interrupted while adding to the Queue","messagePattern":"Got Interrupted while adding to the Queue","errorType":"exception","errorClass":"RejectedExecutionException","httpStatus":null,"severity":"warning","filePath":"processing/src/main/java/org/apache/druid/java/util/common/concurrent/Execs.java","lineNumber":169,"sourceCode":"        nThreads,\n        nThreads,\n        0L,\n        TimeUnit.MILLISECONDS,\n        queue,\n        makeThreadFactory(nameFormat, priority),\n        new RejectedExecutionHandler()\n        {\n          @Override\n          public void rejectedExecution(Runnable r, ThreadPoolExecutor executor)\n          {\n            if (executor.isShutdown()) {\n              throw new RejectedExecutionException(\"Executor is shutdown, rejecting task\");\n            }\n            try {\n              executor.getQueue().put(r);\n            }\n            catch (InterruptedException e) {\n              throw new RejectedExecutionException(\"Got Interrupted while adding to the Queue\", e);\n            }\n          }\n        }\n    );\n  }\n\n  public static ListeningExecutorService directExecutor()\n  {\n    return new DirectExecutorService();\n  }\n}\n","sourceCodeStart":151,"sourceCodeEnd":181,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/common/concurrent/Execs.java#L151-L181","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Increase the executor's queue capacity or add more worker threads so put() rarely blocks","Restore the interrupt status in your caller (Thread.currentThread().interrupt()) if you catch and swallow this exception upstream","Check whether the submitting thread is being interrupted too aggressively (over-eager cancellation/timeouts)","Use offer() with timeout or CallerRunsPolicy-style backpressure instead of indefinite blocking put"],"exampleFix":"// before\nexec.submit(task); // may throw RejectedExecutionException(cause=InterruptedException)\n// after\ntry {\n  exec.submit(task);\n} catch (RejectedExecutionException e) {\n  if (e.getCause() instanceof InterruptedException) {\n    Thread.currentThread().interrupt();\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"// avoid blocking put on a full queue\nboolean accepted = executor.getQueue().offer(task);\nif (!accepted) { /* apply backpressure or reject explicitly */ }","typeGuard":null,"tryCatchPattern":"try {\n  executor.submit(task);\n} catch (RejectedExecutionException e) {\n  if (e.getCause() instanceof InterruptedException) {\n    Thread.currentThread().interrupt(); // preserve interrupt status\n  }\n  throw e;\n}","preventionTips":["Size bounded queues and thread pools for peak producer rates","Avoid interrupting submitter threads except for genuine cancellation","Monitor queue depth/offer latency and alert before saturation","Prefer offer-with-timeout policies over indefinite blocking puts"],"tags":["concurrency","executor","interrupt"],"backgroundTag":"request-timeout","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"}