{"record":{"id":"5dac0d5ba285835c","repo":"apache/druid","slug":"service-is-not-started","errorCode":null,"errorMessage":"Service is not started.","messagePattern":"Service is not started\\.","errorType":"exception","errorClass":"RejectedExecutionException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/emitter/core/HttpPostEmitter.java","lineNumber":205,"sourceCode":"  public void start()\n  {\n    synchronized (startLock) {\n      if (!running) {\n        if (startLatch.getCount() == 0) {\n          throw new IllegalStateException(\"Already started.\");\n        }\n        running = true;\n        startLatch.countDown();\n        emittingThread.start();\n      }\n    }\n  }\n\n  private void awaitStarted()\n  {\n    try {\n      if (!startLatch.await(1, TimeUnit.SECONDS)) {\n        throw new RejectedExecutionException(\"Service is not started.\");\n      }\n      if (isTerminated()) {\n        throw new RejectedExecutionException(\"Service is closed.\");\n      }\n    }\n    catch (InterruptedException e) {\n      log.debug(\"Interrupted waiting for start\");\n      Thread.currentThread().interrupt();\n      throw new RuntimeException(e);\n    }\n  }\n\n  private boolean isTerminated()\n  {\n    return concurrentBatch.get() == null;\n  }\n\n  @Override","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/emitter/core/HttpPostEmitter.java#L187-L223","documentation":"HttpPostEmitter.awaitStarted() waits up to 1 second for the emitter's start latch. If the emitter was never started (or hasn't started within 1s), emit/flush attempts throw RejectedExecutionException 'Service is not started.' This prevents silently queuing events into an emitter that will never send them.","triggerScenarios":"Calling emit(), flush() (via emitAndReturnBatch/flush -> awaitStarted) on an HttpPostEmitter before start() was called, or when start() has not completed within the 1-second await window.","commonSituations":"Forgetting lifecycle start in embedded usage; emitting immediately after construction; a blocked or slow startup thread exceeding the 1s latch timeout; emitter created but start() skipped in tests.","solutions":["Call emitter.start() before emitting or flushing any events","Ensure startup isn't delayed beyond 1 second (check the EmittingThread for blocking initialization)","Check for a prior close/termination that stopped the service; create a fresh emitter if needed","Catch RejectedExecutionException around emit/flush to detect lifecycle misuse and requeue or log"],"exampleFix":"// before\nHttpPostEmitter emitter = new HttpPostEmitter(config, mapper);\nemitter.emit(event); // RejectedExecutionException\n// after\nHttpPostEmitter emitter = new HttpPostEmitter(config, mapper);\nemitter.start();\nemitter.emit(event);","handlingStrategy":"try-catch","validationCode":"if (!emitter.isStarted()) {\n  emitter.start(); // or await startup before emitting\n}","typeGuard":null,"tryCatchPattern":"try {\n  emitter.emit(event);\n} catch (RejectedExecutionException e) {\n  log.warn(\"Emitter not started; starting and re-emitting\");\n  emitter.start();\n  emitter.emit(event);\n}","preventionTips":["Always call start() immediately after constructing HttpPostEmitter","Route emits through Lifecycle so ordering guarantees start-before-emit","Investigate slow EmittingThread startup if the 1s await is exceeded","In tests, start the emitter in setup before any emit/flush calls"],"tags":["lifecycle","rejected-execution","druid"],"backgroundTag":"invalid-state-transition","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}