{"record":{"id":"66613935bd27153d","repo":"apache/seatunnel","slug":"stringutils-stringifyexception-sessionlookupfailur","errorCode":null,"errorMessage":"StringUtils.stringifyException(sessionLookupFailure)","messagePattern":"StringUtils\\.stringifyException\\(sessionLookupFailure\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-file/connector-file-sftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/sftp/system/SFTPConnectionPool.java","lineNumber":289,"sourceCode":"    }\n\n    /**\n     * Close both connection resources, preferring the session captured before the channel can lose\n     * its back-link during cancellation.\n     */\n    private void closeChannel(ChannelSftp channel, Session capturedSession) throws IOException {\n        JSchException sessionLookupFailure = null;\n        Session session = capturedSession;\n        if (session == null) {\n            try {\n                session = channel.getSession();\n            } catch (JSchException e) {\n                sessionLookupFailure = e;\n            }\n        }\n        closeConnectionResources(channel, session);\n        if (sessionLookupFailure != null) {\n            throw new IOException(StringUtils.stringifyException(sessionLookupFailure));\n        }\n    }\n\n    /** Disconnect the SFTP channel and its SSH session when either has already been created. */\n    private void closeConnectionResources(ChannelSftp channel, Session session) {\n        if (channel != null && channel.isConnected()) {\n            channel.disconnect();\n        }\n        if (session != null && session.isConnected()) {\n            session.disconnect();\n        }\n    }\n\n    public int getIdleCount() {\n        return this.idleConnections == null ? 0 : this.idleConnections.size();\n    }\n\n    public int getLiveConnCount() {","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-file/connector-file-sftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/sftp/system/SFTPConnectionPool.java#L271-L307","documentation":"closeChannel disconnects a channel and its SSH session; if retrieving the channel's session (channel.getSession()) itself throws JSchException, the exception is remembered and rethrown as an IOException containing the full trace from StringUtils.stringifyException. It prevents silently leaking an orphaned SSH session when teardown cannot discover the session.","triggerScenarios":"closeChannel(channel, ...) is invoked (from registerConnection failure, shutdown, connect error handling, or disconnect) while the channel is in a state where getSession() fails — e.g. channel already fully disconnected/closed by the remote side.","commonSituations":"Server dropped the connection and the channel object is stale; double-close paths calling closeChannel twice; abrupt network loss making session lookup fail during cleanup.","solutions":["Inspect the embedded stack trace for the underlying JSch cause; if it is benign (already disconnected), ensure close paths avoid double-close (idempotent cleanup)","Upgrade/patch the connector so sessionLookupFailure is only fatal for unexpected states","Treat as a warning-level leak risk: ensure the pool's shutdown eventually cleans sessions; recycle the filesystem afterwards"],"exampleFix":"// before\nchannel.disconnect(); // stale channel later fails getSession()\npool.closeChannel(channel, null);\n// after\nif (channel.isConnected()) { channel.disconnect(); }\n// handle stale channels idempotently","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    poolOp();\n} catch (IOException e) {\n    if (e.getMessage().contains(\"com.jcraft.jsch.JSchException\")) {\n        LOG.warn(\"SFTP cleanup hit stale channel; recycling filesystem\", e);\n        recycleFileSystem();\n    } else throw e;\n}","preventionTips":["Make close/disconnect paths idempotent to avoid double-close on stale channels","Monitor for repeated occurrences — they indicate channels dropped by the remote server","Recycle the filesystem after such cleanup failures to avoid leaks"],"tags":["sftp","cleanup","jsch"],"backgroundTag":"ssh-connection-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}