{"record":{"id":"56081a0eddbb7d9c","repo":"apache/cassandra","slug":"channel-s-transferring-state-is-currently-set-to-t","errorCode":null,"errorMessage":"channel's transferring state is currently set to true. refusing to start new stream","messagePattern":"channel's transferring state is currently set to true\\. refusing to start new stream","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/streaming/async/NettyStreamingChannel.java","lineNumber":131,"sourceCode":"    {\n        return peer();\n    }\n\n    @Override\n    public boolean connected()\n    {\n        return channel.isOpen();\n    }\n\n    public StreamingDataInputPlus in()\n    {\n        return in;\n    }\n\n    public StreamingDataOutputPlus acquireOut()\n    {\n        if (!channel.attr(TRANSFERRING_FILE_ATTR).compareAndSet(false, true))\n            throw new IllegalStateException(\"channel's transferring state is currently set to true. refusing to start new stream\");\n\n        return new AsyncStreamingOutputPlus(channel)\n        {\n            @Override\n            public void close() throws IOException\n            {\n                try\n                {\n                    super.close();\n                }\n                finally\n                {\n                    NettyStreamingChannel.this.channel.attr(TRANSFERRING_FILE_ATTR).set(FALSE);\n                }\n            }\n        };\n    }\n","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/streaming/async/NettyStreamingChannel.java#L113-L149","documentation":"NettyStreamingChannel multiplexes stream transfers over one connection, using a TRANSFERRING_FILE_ATTR flag to guarantee only one outbound transfer at a time. acquireOut() uses compareAndSet(false, true); if the flag is already true, another transfer holds the channel, and it throws this IllegalStateException rather than interleaving transfers.","triggerScenarios":"Calling acquireOut() on a NettyStreamingChannel that already has an active transfer — e.g. submitting a second FileStreamTask on the same channel while a file is still being transferred, or a leak where a previous transfer never released the flag (close not called).","commonSituations":"High streaming concurrency saturating the per-session channel pool; an earlier transfer aborted by exception without closing the AsyncStreamingOutputPlus (flag never reset); simultaneous repairs/streams hitting the same peer.","solutions":["Ensure acquireOut() results are always closed (try-with-resources) so TRANSFERRING_FILE_ATTR resets; look for leaked transfers on the channel.","Reduce streaming concurrency (stream_throughput_outbound, concurrent stream sessions) so fewer transfers contend per channel.","Check for stuck prior transfers (long-running FileStreamTask) to the peer and cancel/retry the session.","Upgrade to a version where channel acquisition is queued rather than failing hard, or retry the stream session after the current transfer completes."],"exampleFix":"// before\nStreamingDataOutputPlus out = channel.acquireOut();\nout.write(...);\n// flag may stay set on exception\n// after\ntry (StreamingDataOutputPlus out = channel.acquireOut()) {\n    out.write(...);\n} // close() resets TRANSFERRING_FILE_ATTR","handlingStrategy":"try-catch","validationCode":"if (channel.attr(TRANSFERRING_FILE_ATTR).get()) { /* wait or pick another channel */ }","typeGuard":null,"tryCatchPattern":"try (StreamingDataOutputPlus out = channel.acquireOut()) { out.write(...); } catch (IllegalStateException e) { if (e.getMessage().contains(\"transferring state\")) { retryAfterCurrentTransfer(); } else { throw e; } }","preventionTips":["Always use try-with-resources for acquireOut() results so the flag resets on failure.","Limit concurrent streaming sessions/throughput per peer.","Monitor for stuck transfers that never release the channel."],"tags":["streaming","netty","concurrency","resource-leak"],"backgroundTag":"resource-busy","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}