{"record":{"id":"6234d7ad3596dafb","repo":"aeron-io/aeron","slug":"existing-max-write-time-counter-detected-for-archiveid","errorCode":null,"errorMessage":"existing max write time counter detected for archiveId=${archiveId}","messagePattern":"existing max write time counter detected for archiveId=(.+?)","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"aeron-archive/src/main/java/io/aeron/archive/Archive.java","lineNumber":1593,"sourceCode":"\n            if (null == replaySessionCounter)\n            {\n                replaySessionCounter = ArchiveCounters.allocate(\n                    aeron,\n                    tempBuffer,\n                    ARCHIVE_REPLAY_SESSION_COUNT_TYPE_ID,\n                    \"Archive Replay Sessions\",\n                    archiveId);\n            }\n            validateCounterTypeId(aeron, replaySessionCounter, ARCHIVE_REPLAY_SESSION_COUNT_TYPE_ID);\n\n            if (null == maxWriteTimeCounter)\n            {\n                final int counterId = ArchiveCounters.find(\n                    aeron.countersReader(), ARCHIVE_RECORDER_MAX_WRITE_TIME_TYPE_ID, archiveId);\n                if (NULL_VALUE != counterId)\n                {\n                    throw new ConfigurationException(\n                        \"existing max write time counter detected for archiveId=\" + archiveId);\n                }\n\n                maxWriteTimeCounter = ArchiveCounters.allocate(\n                    aeron,\n                    tempBuffer,\n                    ARCHIVE_RECORDER_MAX_WRITE_TIME_TYPE_ID,\n                    \"archive-recorder max write time in ns\",\n                    archiveId);\n            }\n            validateCounterTypeId(aeron, maxWriteTimeCounter, ARCHIVE_RECORDER_MAX_WRITE_TIME_TYPE_ID);\n\n            if (null == totalWriteBytesCounter)\n            {\n                totalWriteBytesCounter = ArchiveCounters.allocate(\n                    aeron,\n                    tempBuffer,\n                    ARCHIVE_RECORDER_TOTAL_WRITE_BYTES_TYPE_ID,","sourceCodeStart":1575,"sourceCodeEnd":1611,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-archive/src/main/java/io/aeron/archive/Archive.java#L1575-L1611","documentation":"To avoid duplicate recording max-write-time counters for the same archiveId (e.g. from a previous archive instance that did not clean up), Archive checks the counters reader for an existing counter with ARCHIVE_RECORDER_MAX_WRITE_TIME_TYPE_ID and the given archiveId. If one already exists and no counter was supplied, Archive throws ConfigurationException.","triggerScenarios":"Starting a second Archive (or restarting without the driver's counter cleanup) using the same archiveId while the old max-write-time counter is still live in the driver's counter buffer.","commonSituations":"Rapid restart of an embedded archive against a still-running media driver; launching two archive instances with a clashing archiveId.","solutions":["Use a unique archiveId, or ensure the previous archive instance was fully closed so its counters are released.","Restart the media driver to clear stale counters if a crashed process left them behind.","Explicitly supply the existing maxWriteTimeCounter via Archive.Context if intentional reuse is desired."],"exampleFix":"// before\nArchive.launch(new Archive.Context().archiveId(42)); // stale counter for 42 exists\n// after\nArchive.launch(new Archive.Context().archiveId(System.nanoTime())); // or ensure old archive closed","handlingStrategy":"try-catch","validationCode":"int existing = ArchiveCounters.find(aeron.countersReader(),\n    ArchiveCounters.ARCHIVE_RECORDER_MAX_WRITE_TIME_TYPE_ID, archiveId);\nif (existing != Aeron.NULL_VALUE)\n{\n    archiveId = generateNewArchiveId(); // pick an unused id before launch\n}","typeGuard":null,"tryCatchPattern":"try {\n    Archive.launch(ctx.archiveId(archiveId));\n} catch (ConfigurationException e) {\n    if (e.getMessage().contains(\"existing max write time counter\")) {\n        // retry with a fresh archiveId after closing the stale archive\n    }\n}","preventionTips":["Always close previous Archive instances cleanly before restarting with the same archiveId","Generate unique archiveIds for concurrent archive instances"],"tags":["aeron","archive","counters","state"],"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-15T23:17:13.987Z"}