{"record":{"id":"851db82fdd2fa025","repo":"aeron-io/aeron","slug":"existing-publication-has-clashing-sessionid-sessionid-for","errorCode":null,"errorMessage":"existing publication has clashing sessionId=${sessionId} for streamId=${streamId} channel=${originalChannel}","messagePattern":"existing publication has clashing sessionId=(.+?) for streamId=(.+?) channel=(.+?)","errorType":"exception","errorClass":"InvalidChannelException","httpStatus":null,"severity":"error","filePath":"aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java","lineNumber":2019,"sourceCode":"        {\n            final SubscriptionLink subscription = subscriptionLinks.get(i);\n            if (subscription.registrationId() == registrationId && subscription.channel().equals(channel))\n            {\n                subscriptionLink = subscription;\n                fastUnorderedRemove(subscriptionLinks, i);\n                break;\n            }\n        }\n\n        return subscriptionLink;\n    }\n\n    private void checkForSessionClash(\n        final int sessionId, final int streamId, final String channel, final String originalChannel)\n    {\n        if (activeSessionSet.contains(new SessionKey(sessionId, streamId, channel)))\n        {\n            throw new InvalidChannelException(\"existing publication has clashing sessionId=\" + sessionId +\n                \" for streamId=\" + streamId + \" channel=\" + originalChannel);\n        }\n    }\n\n    private <T extends DriverManagedResource> void checkManagedResources(\n        final ArrayList<T> list, final long nowNs, final long nowMs)\n    {\n        for (int lastIndex = list.size() - 1, i = lastIndex; i >= 0; i--)\n        {\n            final DriverManagedResource resource = list.get(i);\n\n            resource.onTimeEvent(nowNs, nowMs, this);\n\n            if (resource.hasReachedEndOfLife())\n            {\n                fastUnorderedRemove(list, i, lastIndex--);\n\n                try","sourceCodeStart":2001,"sourceCodeEnd":2037,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java#L2001-L2037","documentation":"Aeron publications are keyed by (sessionId, streamId, canonical channel). When adding a new publication whose generated or requested sessionId already exists in the driver's activeSessionSet, this InvalidChannelException is thrown to prevent two publications colliding on the same stream identity.","triggerScenarios":"Calling addPublication/addExclusivePublication with an explicit session-id that equals an active publication's session-id on the same stream/channel; rare random sessionId collision when the driver assigns one; re-adding a publication while the old one is still draining.","commonSituations":"Manually pinning session-id=? in URIs for stream routing and reusing the value; rapid reconnect loops recreating publications before cleanup; multiple services using the same fixed session-id on a shared stream.","solutions":["Omit session-id from the URI and let the driver pick a unique one","Choose a different explicit session-id that is not currently in use","Wait for the previous publication (and its drain/cleanup) to complete before re-adding with the same id","Coordinate session-id allocation across services sharing the stream"],"exampleFix":"// before\naeron.addExclusivePublication(\"aeron:udp?endpoint=localhost:40456|session-id=12345\", 1001);\n// after\naeron.addExclusivePublication(\"aeron:udp?endpoint=localhost:40456\", 1001); // driver assigns unique sessionId","handlingStrategy":"validation","validationCode":"Integer sessionId = uriParamInt(channel, \"session-id\", null);\nif (sessionId != null && activeSessions.contains(sessionId, streamId, canonicalChannel)) {\n    throw new IllegalArgumentException(\"session-id \" + sessionId + \" already active on \" + streamId);\n}","typeGuard":null,"tryCatchPattern":"try { aeron.addExclusivePublication(channel, streamId); } catch (InvalidChannelException e) { if (e.getMessage().contains(\"clashing sessionId\")) { /* retry without explicit session-id */ } }","preventionTips":["Let the driver assign session-ids unless you have a specific routing need","Allocate explicit session-ids from a coordinated range per producer","Add retry logic that re-adds without session-id on clash","Avoid rapid publication churn that can race with cleanup"],"tags":["aeron","publication","session-id","conflict"],"backgroundTag":"conflicting-config-options","analyzedSha":"6d60124e15e35c11b49ba2e3c2c2858a09a18803","analyzedAt":"2026-09-12T11:17:07.683Z","contentChangedAt":"2026-09-12T11:17:07.683Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}