{"record":{"id":"686ba32f5db41460","repo":"apache/seatunnel","slug":"failed-to-close-ssh-session","errorCode":null,"errorMessage":"Failed to close ssh session","messagePattern":"Failed to close ssh session","errorType":"exception","errorClass":"ClickhouseConnectorException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/sink/file/RsyncFileTransfer.java","lineNumber":180,"sourceCode":"        }\n    }\n\n    @Override\n    public void transferAndChown(List<String> sourcePaths, String targetPath) {\n        if (sourcePaths == null) {\n            throw new ClickhouseConnectorException(\n                    CommonErrorCodeDeprecated.ILLEGAL_ARGUMENT, \"sourcePath is null\");\n        }\n        sourcePaths.forEach(sourcePath -> transferAndChown(sourcePath, targetPath));\n    }\n\n    @Override\n    public void close() {\n        if (clientSession != null && clientSession.isOpen()) {\n            try {\n                clientSession.close();\n            } catch (IOException e) {\n                throw new ClickhouseConnectorException(\n                        ClickhouseConnectorErrorCode.SSH_OPERATION_FAILED,\n                        \"Failed to close ssh session\",\n                        e);\n            }\n        }\n        if (sshClient != null && sshClient.isOpen()) {\n            sshClient.stop();\n            try {\n                sshClient.close();\n            } catch (IOException e) {\n                throw new ClickhouseConnectorException(\n                        ClickhouseConnectorErrorCode.SSH_OPERATION_FAILED,\n                        \"Failed to close ssh client\",\n                        e);\n            }\n        }\n    }\n}","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/sink/file/RsyncFileTransfer.java#L162-L198","documentation":"RsyncFileTransfer.close() wraps any IOException thrown while closing the Apache SSHD clientSession into a ClickhouseConnectorException with SSH_OPERATION_FAILED. This fires during sink cleanup when the SSH connection to the remote host is already broken or the session teardown fails. It signals that resources may not have been released cleanly.","triggerScenarios":"Sink close() is called and clientSession.close() throws IOException — typically because the network connection dropped mid-job, the SSH server closed the connection abruptly, or the session was already half-closed by a timeout.","commonSituations":"Long-running ClickHouse rsync-based file transfers where an idle SSH session was reaped by a firewall/NAT, remote ClickHouse host restarted during the job, or SSH server IdleTimeout terminated the session before close().","solutions":["Verify network stability and SSH server KeepAlive/timeout settings between SeaTunnel worker and the ClickHouse host","Check sshd logs on the remote host for connection resets around the failure time","Retry the job; if intermittent, this is a transient network issue","Upgrade connector/sshd-common dependency if the close-failure stems from a known Apache SSHD bug"],"exampleFix":"// before: no keepalive configured\nSshClient sshClient = SshClient.setUpDefaultClient();\nsshClient.start();\n// after: enable heartbeats so idle sessions are not reaped\nClientFactoryManager manager = sshClient;\nmanager.setKeepAliveProvider(KeepAliveProvider.KEEP_ALIVE);\nmanager.setProperty(ClientFactoryManager.HEARTBEAT_INTERVAL, 30000);","handlingStrategy":"try-catch","validationCode":"// before job: verify SSH reachability\nssh -o ConnectTimeout=5 -o BatchMode=yes user@host true && echo OK","typeGuard":null,"tryCatchPattern":"try {\n    sink.close();\n} catch (ClickhouseConnectorException e) {\n    if (e.getErrorCode() == ClickhouseConnectorErrorCode.SSH_OPERATION_FAILED) {\n        log.warn(\"SSH session close failed (possibly already dead connection), continuing\", e);\n    } else { throw e; }\n}","preventionTips":["Configure SSH keepalive/heartbeat intervals to survive idle periods","Avoid firewall/NAT idle timeouts shorter than job duration","Monitor sshd logs for dropped connections"],"tags":["ssh","network","resource-cleanup","clickhouse"],"backgroundTag":"network-request-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}