{"record":{"id":"713f3f1459b46748","repo":"apache/druid","slug":"failed-to-close-one-or-more-emitters","errorCode":null,"errorMessage":"failed to close one or more emitters","messagePattern":"failed to close one or more emitters","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/emitter/core/ComposingEmitter.java","lineNumber":102,"sourceCode":"  @LifecycleStop\n  public void close() throws IOException\n  {\n    boolean fail = false;\n    log.info(\"Closing Composing Emitter.\");\n\n    for (Emitter e : emitters) {\n      try {\n        log.info(\"Closing emitter %s.\", e.getClass().getName());\n        e.close();\n      }\n      catch (IOException ex) {\n        log.error(ex, \"Failed to close emitter [%s]\", e.getClass().getName());\n        fail = true;\n      }\n    }\n\n    if (fail) {\n      throw new IOException(\"failed to close one or more emitters\");\n    }\n  }\n\n  @Override\n  public String toString()\n  {\n    return \"ComposingEmitter{\" +\n           \"emitters=\" + emitters +\n           '}';\n  }\n}\n","sourceCodeStart":84,"sourceCodeEnd":114,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/emitter/core/ComposingEmitter.java#L84-L114","documentation":"ComposingEmitter.close() attempts to close each child emitter; if any child close fails it logs the failure and, after processing all children, throws IOException 'failed to close one or more emitters'. This guarantees all children get a close attempt while still surfacing resource-cleanup problems to the caller.","triggerScenarios":"Calling close() on a ComposingEmitter when at least one wrapped emitter's close() throws (e.g. HttpPostEmitter's terminating flush fails, socket close errors).","commonSituations":"Application shutdown with a dead HTTP recipient causing the final flush inside close to fail; double-close of a child emitter; interrupted emitting thread refusing to terminate.","solutions":["Check logs for 'Failed to close emitter [...]' to find the offending child emitter","Ensure the recipient endpoints are reachable at shutdown so the final flush inside close succeeds","Call flush() before close() to reduce the work close must do","Catch and log IOException from close in shutdown hooks so remaining cleanup still runs"],"exampleFix":"// before\nemitter.close(); // throws if any child fails\n// after\ntry {\n  emitter.close();\n} catch (IOException e) {\n  log.error(e, \"Some emitters failed to close\");\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  emitter.close();\n} catch (IOException e) {\n  log.error(e, \"One or more emitters failed to close; possible event loss\");\n}","preventionTips":["Call flush() successfully before close() to minimize final-flush failures","Ensure recipients are reachable during shutdown","Always close emitters in a finally block or shutdown hook","Log but do not rethrow in shutdown paths so other cleanup proceeds"],"tags":["io","resource-cleanup","emitter"],"backgroundTag":"file-write-failed","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"}