{"record":{"id":"785e90287bf3f039","repo":"aeron-io/aeron","slug":"publication-is-closed","errorCode":null,"errorMessage":"Publication is closed","messagePattern":"Publication is closed","errorType":"exception","errorClass":"AeronException","httpStatus":null,"severity":"error","filePath":"aeron-client/src/main/java/io/aeron/Publication.java","lineNumber":568,"sourceCode":"     * @param bufferClaim to be populated if the claim succeeds.\n     * @return The new stream position, otherwise a negative error value of {@link #NOT_CONNECTED},\n     * {@link #BACK_PRESSURED}, {@link #ADMIN_ACTION}, {@link #CLOSED}, or {@link #MAX_POSITION_EXCEEDED}.\n     * @throws IllegalArgumentException if the length is greater than {@link #maxPayloadLength()} within an MTU.\n     * @see BufferClaim#commit()\n     * @see BufferClaim#abort()\n     */\n    public abstract long tryClaim(int length, BufferClaim bufferClaim);\n\n    /**\n     * Add a destination manually to a multi-destination-cast Publication.\n     *\n     * @param endpointChannel for the destination to add.\n     */\n    public void addDestination(final String endpointChannel)\n    {\n        if (isClosed)\n        {\n            throw new AeronException(\"Publication is closed\");\n        }\n\n        conductor.addDestination(originalRegistrationId, endpointChannel);\n    }\n\n    /**\n     * Remove a previously added destination manually from a multi-destination-cast Publication.\n     *\n     * @param endpointChannel for the destination to remove.\n     */\n    public void removeDestination(final String endpointChannel)\n    {\n        if (isClosed)\n        {\n            throw new AeronException(\"Publication is closed\");\n        }\n\n        conductor.removeDestination(originalRegistrationId, endpointChannel);","sourceCodeStart":550,"sourceCodeEnd":586,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-client/src/main/java/io/aeron/Publication.java#L550-L586","documentation":"Publication.addDestination() throws this AeronException when the publication has already been closed. Once closed, its conductor can no longer process destination changes for the (multi-destination) publication.","triggerScenarios":"Calling publication.addDestination(endpointChannel) after close() was called, after the publication was closed via the Aeron client, or racing with an async close from another thread / the client conductor closing a released publication.","commonSituations":"MDC (multi-destination-cast) publications being reconfigured during shutdown; lifecycle bugs where a destination is added in a cleanup path after publication.close(); holding publication references after Aeron.close().","solutions":["Check publication.isClosed() before calling addDestination.","Reorder lifecycle code so all addDestination calls happen before close(), and remove destinations from shutdown paths.","Guard destination management with the same lock/ownership discipline that closes the publication to eliminate the race."],"exampleFix":"// before\npublication.addDestination(\"aeron:udp?endpoint=localhost:40456\");\n// after\nif (!publication.isClosed()) {\n    publication.addDestination(\"aeron:udp?endpoint=localhost:40456\");\n}","handlingStrategy":"try-catch","validationCode":"if (publication.isClosed()) {\n    return; // skip destination management\n}","typeGuard":null,"tryCatchPattern":"try {\n    publication.addDestination(uri);\n} catch (AeronException e) {\n    if (\"Publication is closed\".equals(e.getMessage())) {\n        // publication torn down; abandon reconfiguration\n    } else {\n        throw e;\n    }\n}","preventionTips":["Check isClosed() before any destination operation.","Centralize publication lifecycle in one owner thread.","Avoid adding/removing destinations from shutdown/cleanup paths."],"tags":["aeron","publication","closed-resource","lifecycle"],"backgroundTag":"invalid-state-transition","analyzedSha":"6d60124e15e35c11b49ba2e3c2c2858a09a18803","analyzedAt":"2026-09-12T11:17:07.683Z","contentChangedAt":"2026-09-12T11:17:07.683Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}