{"record":{"id":"2d0c76e1afca0b73","repo":"aeron-io/aeron","slug":"log-publication-is-closed","errorCode":null,"errorMessage":"log publication is closed","messagePattern":"log publication is closed","errorType":"exception","errorClass":"ClusterException","httpStatus":null,"severity":"error","filePath":"aeron-cluster/src/main/java/io/aeron/cluster/LogPublisher.java","lineNumber":325,"sourceCode":"                    .timeUnit(ClusterClock.map(timeUnit))\n                    .appVersion(appVersion);\n\n                bufferClaim.commit();\n                return true;\n            }\n\n            checkResult(position, publication);\n        }\n        while (--attempts > 0);\n\n        return false;\n    }\n\n    private static void checkResult(final long position, final Publication publication)\n    {\n        if (Publication.CLOSED == position)\n        {\n            throw new ClusterException(\"log publication is closed\");\n        }\n\n        if (Publication.MAX_POSITION_EXCEEDED == position)\n        {\n            throw new ClusterException(\n                \"log publication at max position: term-length=\" + publication.termBufferLength());\n        }\n    }\n\n    /**\n     * {@inheritDoc}\n     */\n    @Override\n    public String toString()\n    {\n        return \"LogPublisher{\" +\n            \"destinationChannel='\" + destinationChannel + '\\'' +\n            '}';","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-cluster/src/main/java/io/aeron/cluster/LogPublisher.java#L307-L343","documentation":"LogPublisher.checkResult inspects the return position of Publication.offer/tryClaim on the cluster log publication. Aeron's Publication returns CLOSED when the underlying publication has been closed; appending to a closed log is impossible, so a ClusterException is thrown. In a cluster this effectively means this member can no longer act as leader/appender.","triggerScenarios":"Any append attempt (appendMessage, appendSessionOpen, appendSessionClose, appendTimer, appendClusterAction, appendNewLeadershipTermEvent) after the log Publication was closed — e.g. after a leadership change closed the old publication, or after stop/close of the cluster media driver.","commonSituations":"A leadership transition or election closed the publication while the old leader still tried to append; calling into the cluster API during shutdown; a race between closing the publication and pending appends.","solutions":["Ensure the publication is not closed before appending (check publication.isClosed())","Verify the leadership/election lifecycle: only the current leader should hold an open log publication","Check that the media driver / archive was not stopped while the cluster is appending","Increase logging around publication close to find who closed it prematurely"],"exampleFix":"// before\nlogPublisher.appendMessage(buffer, offset, length, nowNs);\n// after\nif (!publication.isClosed()) {\n    logPublisher.appendMessage(buffer, offset, length, nowNs);\n}","handlingStrategy":"try-catch","validationCode":"if (publication.isClosed()) { /* re-establish leadership/publication first */ }","typeGuard":"boolean canAppend(Publication p) { return p != null && !p.isClosed(); }","tryCatchPattern":"try { publisher.appendMessage(...); } catch (ClusterException e) { /* election lost / shutdown: stop appending */ }","preventionTips":["Only the current leader appends to the log","Track publication lifecycle vs election transitions","Don't call cluster append APIs during shutdown"],"tags":["aeron-cluster","publication","closed-resource","leader"],"backgroundTag":"resource-closed","analyzedSha":"6d60124e15e35c11b49ba2e3c2c2858a09a18803","analyzedAt":"2026-09-12T11:17:07.683Z","contentChangedAt":"2026-09-12T11:17:07.683Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}