{"record":{"id":"379317acc679141d","repo":"aeron-io/aeron","slug":"client-is-closed-aeron","errorCode":null,"errorMessage":"client is closed","messagePattern":"client is closed","errorType":"exception","errorClass":"AeronException","httpStatus":null,"severity":"error","filePath":"aeron-client/src/main/java/io/aeron/Aeron.java","lineNumber":497,"sourceCode":"    {\n        return conductor.getSubscription(registrationId);\n    }\n\n    /**\n     * Generate the next correlation id that is unique for the connected media driver.\n     * <p>\n     * This is useful generating correlation identifiers for pairing requests with responses in a clients own\n     * application protocol.\n     * <p>\n     * This method is thread safe and will work across processes that all use the same media driver.\n     *\n     * @return next correlation id that is unique for the media driver.\n     */\n    public long nextCorrelationId()\n    {\n        if (isClosed)\n        {\n            throw new AeronException(\"client is closed\");\n        }\n\n        return commandBuffer.nextCorrelationId();\n    }\n\n    /**\n     * Get next available session id from the media driver. The session id will be unique for the connected media\n     * driver and given {@code streamId}.\n     * <p>\n     * If media driver's version is 1.49.0 or higher, then the session id is returned by the media driver. Otherwise,\n     * a random session id is generated.\n     *\n     * @param streamId for which a new session id is requested. Media driver only checks for session clashes at the\n     *                 stream level.\n     * @return next available session id that is unique for the media driver and given {@code streamId}.\n     * @since 1.49.0\n     */\n    public int nextSessionId(final int streamId)","sourceCodeStart":479,"sourceCodeEnd":515,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-client/src/main/java/io/aeron/Aeron.java#L479-L515","documentation":"Aeron.nextCorrelationId allocates ids from the client's driver command buffer; if the client has been closed, the command buffer is gone, so the method throws AeronException 'client is closed'. Callers must not use an Aeron instance after close().","triggerScenarios":"Calling aeron.nextCorrelationId() after Aeron.close() or after the client was closed by the driver (e.g. driver termination or ERROR injection leading to client close).","commonSituations":"Shutdown races where a background thread still issues commands while the main thread closes Aeron; holding a stale Aeron reference after a driver restart; long-lived caches storing Aeron instances.","solutions":["Ensure the Aeron instance outlives all users, or guard calls with aeron.isClosed() / isClosed flag","Synchronize shutdown so all threads stop publishing/requesting before Aeron.close()","Recreate the Aeron instance (Aeron.connect) if the driver restarted","Use try-with-resources or a lifecycle manager for Aeron"],"exampleFix":"// before\nlong id = aeron.nextCorrelationId(); // may throw after close\n// after\nif (aeron.isClosed()) { aeron = Aeron.connect(ctx); }\nlong id = aeron.nextCorrelationId();","handlingStrategy":"try-catch","validationCode":"if (aeron == null || aeron.isClosed()) { aeron = Aeron.connect(ctx); }","typeGuard":"boolean isUsable(Aeron aeron) { return aeron != null && !aeron.isClosed(); }","tryCatchPattern":"try { long id = aeron.nextCorrelationId(); }\ncatch (AeronException e) { if (\"client is closed\".equals(e.getMessage())) { aeron = Aeron.connect(ctx); id = aeron.nextCorrelationId(); } }","preventionTips":["Coordinate close() with all threads using the client","Check isClosed() before issuing commands during shutdown","Wrap Aeron lifecycle in a manager that recreates the client on driver restart"],"tags":["lifecycle","client-closed","aeron","shutdown"],"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"}