{"record":{"id":"84e3606ffbea7ae5","repo":"apache/druid","slug":"failed-to-flush-one-or-more-emitters-84e360","errorCode":null,"errorMessage":"failed to flush one or more emitters","messagePattern":"failed to flush one or more emitters","errorType":"error_code","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/emitter/core/SwitchingEmitter.java","lineNumber":137,"sourceCode":"  @Override\n  public void flush() throws IOException\n  {\n    boolean fail = false;\n    log.info(\"Flushing Switching Emitter.\");\n\n    for (Emitter e : knownEmitters) {\n      try {\n        log.info(\"Flushing emitter %s.\", e.getClass().getName());\n        e.flush();\n      }\n      catch (IOException ex) {\n        log.error(ex, \"Failed to flush emitter [%s]\", e.getClass().getName());\n        fail = true;\n      }\n    }\n\n    if (fail) {\n      throw new IOException(\"failed to flush one or more emitters\");\n    }\n  }\n\n  /**\n   * Closes all emitters that the SwitchingEmitter uses\n   * @throws IOException\n   */\n  @Override\n  @LifecycleStop\n  public void close() throws IOException\n  {\n    boolean fail = false;\n    log.info(\"Closing Switching Emitter.\");\n\n    for (Emitter e : knownEmitters) {\n      try {\n        log.info(\"Closing emitter %s.\", e.getClass().getName());\n        e.close();","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/emitter/core/SwitchingEmitter.java#L119-L155","documentation":"SwitchingEmitter.flush() flushes each of its delegate emitters; if any delegate throws, it logs the failure and sets a fail flag, then after processing all delegates throws a single IOException('failed to flush one or more emitters'). The specific delegate's error is only available in the logged stack trace, so this exception aggregates any underlying flush failure (timeouts, interruptions, closed services).","triggerScenarios":"Calling flush() (or close(), which flushes) when any wrapped emitter — e.g. an HttpPostEmitter that timed out or a closed emitter — fails its own flush.","commonSituations":"Shutdown where the HTTP delegate can't reach the recipient; mixed delegate setup where one feed's emitter is misconfigured; periodic flush hitting a network outage.","solutions":["Inspect the preceding 'Failed to flush emitter [%s]' log lines to identify which delegate failed and why.","Fix the underlying delegate issue (network, flushTimeOut, endpoint availability).","Catch IOException around flush()/close() in shutdown paths so one bad emitter doesn't abort shutdown.","Test each delegate emitter's connectivity independently before wiring into SwitchingEmitter."],"exampleFix":"// before\ntry { switchingEmitter.close(); } catch (Exception ignored) {}\n// after\ntry {\n  switchingEmitter.close();\n} catch (IOException e) {\n  log.error(e, \"Some delegate emitters failed to flush; check delegate logs\");\n}","handlingStrategy":"try-catch","validationCode":"// proactively verify each delegate can flush\nfor (Emitter delegate : delegates) {\n  try { delegate.flush(); } catch (IOException e) { log.error(e, \"Delegate unhealthy: %s\", delegate); }\n}","typeGuard":null,"tryCatchPattern":"try {\n  switchingEmitter.flush();\n} catch (IOException e) {\n  // check 'Failed to flush emitter' log lines to find the failing delegate\n  log.error(e, \"One or more delegate emitters failed to flush\");\n}","preventionTips":["Monitor delegate emitter logs for flush failures","Ensure each delegate's endpoint/timeout config is correct","Handle flush IOException gracefully in shutdown paths"],"tags":["aggregated-failure","flush","switching-emitter"],"backgroundTag":"http-error-response","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"}