{"record":{"id":"35e0524c856f20c7","repo":"aeron-io/aeron","slug":"failed-to-send-stop-replay-request","errorCode":null,"errorMessage":"failed to send stop replay request","messagePattern":"failed to send stop replay request","errorType":"exception","errorClass":"ArchiveException","httpStatus":null,"severity":"error","filePath":"aeron-archive/src/main/java/io/aeron/archive/client/AeronArchive.java","lineNumber":1182,"sourceCode":"    /**\n     * Stop an existing replay session.\n     *\n     * @param replaySessionId to stop replay for which would have been returned from\n     *                        {@link #startReplay(long, long, long, String, int)}.\n     */\n    public void stopReplay(final long replaySessionId)\n    {\n        lock.lock();\n        try\n        {\n            ensureConnected();\n            ensureNotReentrant();\n\n            lastCorrelationId = aeron.nextCorrelationId();\n\n            if (!archiveProxy.stopReplay(replaySessionId, lastCorrelationId, controlSessionId))\n            {\n                throw new ArchiveException(\"failed to send stop replay request\");\n            }\n\n            pollForResponse(lastCorrelationId);\n        }\n        finally\n        {\n            lock.unlock();\n        }\n    }\n\n    /**\n     * Stop all replay sessions for a given recording id or all replays in general.\n     *\n     * @param recordingId to stop replay for or {@link Aeron#NULL_VALUE} for all replays.\n     */\n    public void stopAllReplays(final long recordingId)\n    {\n        lock.lock();","sourceCodeStart":1164,"sourceCodeEnd":1200,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-archive/src/main/java/io/aeron/archive/client/AeronArchive.java#L1164-L1200","documentation":"stopReplay sends a STOP_REPLAY request for a specific replay session id. ArchiveProxy.stopReplay returning false — control-request publication not connected, offer failed from backpressure, or closed publication — means the request was never dispatched, so the library throws this ArchiveException.","triggerScenarios":"Calling stopReplay(replaySessionId) when the archive control channel is disconnected (archive stopped/restarted, network fault) or the control stream is backpressured; also when the control session was already terminated.","commonSituations":"Cleanup code in finally blocks running after an archive outage; replay teardown scripts racing with archive shutdown; long-lived sessions whose control publication silently dropped.","solutions":["Check the archive is up and control channel is connected; reconnect via AeronArchive.connect if the session was lost.","Retry with backoff for transient backpressure — the replay will end on its own when its subscription closes anyway.","Validate replaySessionId belongs to the current control session; stale session ids from a previous connection cannot be stopped.","If the replay is already gone (archive restarted), treat the failure as benign and move on."],"exampleFix":"// before\narchive.stopReplay(replaySessionId);\n\n// after\ntry {\n    archive.stopReplay(replaySessionId);\n} catch (ArchiveException e) {\n    archive = AeronArchive.connect(archiveCtx);\n    archive.stopAllReplays(recordingId); // best-effort cleanup\n}","handlingStrategy":"try-catch","validationCode":"if (replaySessionId <= 0) throw new IllegalArgumentException(\"invalid replaySessionId\");\nboolean connected = archive != null && !archive.isClosed();","typeGuard":"boolean stoppable(AeronArchive a, long sid) { return a != null && !a.isClosed() && a.state() == AeronArchive.State.CONNECTED && sid > 0; }","tryCatchPattern":"try {\n    archive.stopReplay(replaySessionId);\n} catch (ArchiveException e) {\n    // replay may already be gone after archive restart; log and continue\n    logger.warn(\"stopReplay send failed for session {}\", replaySessionId, e);\n}","preventionTips":["Treat stopReplay failures in cleanup paths as best-effort; don't crash teardown.","Reconnect only if further archive calls are needed.","Track replay session ids per control session; stale ids can't be stopped.","Avoid racing stopReplay with archive shutdown."],"tags":["aeron","archive","replay","network"],"backgroundTag":"api-request-failed","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"}