{"record":{"id":"2fd40081eb06ae69","repo":"apache/seatunnel","slug":"close-cql-session-failed","errorCode":"CLOSE_CQL_SESSION_FAILED","errorMessage":"CLOSE_CQL_SESSION_FAILED","messagePattern":"CLOSE_CQL_SESSION_FAILED","errorType":"error_code","errorClass":"CassandraConnectorException","httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-cassandra/src/main/java/org/apache/seatunnel/connectors/seatunnel/cassandra/sink/CassandraSinkWriter.java","lineNumber":154,"sourceCode":"    private String initPrepareCQL() {\n        String[] placeholder = new String[cassandraParameters.getFields().size()];\n        Arrays.fill(placeholder, \"?\");\n        return String.format(\n                \"INSERT INTO %s (%s) VALUES (%s)\",\n                cassandraParameters.getTable(),\n                String.join(\",\", cassandraParameters.getFields()),\n                String.join(\",\", placeholder));\n    }\n\n    @Override\n    public void close() throws IOException {\n        flush();\n        try {\n            if (this.session != null) {\n                this.session.close();\n            }\n        } catch (Exception e) {\n            throw new CassandraConnectorException(\n                    CassandraConnectorErrorCode.CLOSE_CQL_SESSION_FAILED, e);\n        }\n    }\n}\n","sourceCodeStart":136,"sourceCodeEnd":159,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-cassandra/src/main/java/org/apache/seatunnel/connectors/seatunnel/cassandra/sink/CassandraSinkWriter.java#L136-L159","documentation":"CassandraSinkWriter.close() flushes then closes the CqlSession; if session.close() throws, the error is wrapped as CLOSE_CQL_SESSION_FAILED. The writer already flushed successfully, so pending data is safe — but the session cleanup failed, typically due to broken connections during shutdown.","triggerScenarios":"this.session.close() throws — happens when the driver's channels are already dead (cluster restarted/network partitioned), or when close is racing with in-flight async writes that hold onto the session.","commonSituations":"Cassandra cluster unavailability at job shutdown; very short-lived tasks where the node disconnected before close; driver force-closing channels with in-flight requests.","solutions":["Usually safe to ignore for data correctness (flush already succeeded); verify checkpoint completed and data landed in the table.","Check Cassandra node logs for disconnect reasons; fix network instability or node restarts during job lifetime.","Ensure async writes are fully completed before close — increase flush/await windows if in-flight requests overlap shutdown.","Upgrade the Cassandra Java driver if close consistently throws after healthy writes (known channel-close race issues)."],"exampleFix":"// before\ntry {\n    if (this.session != null) {\n        this.session.close();\n    }\n} catch (Exception e) {\n    throw new CassandraConnectorException(CLOSE_CQL_SESSION_FAILED, e);\n}\n// after (application-side guard)\ntry (SinkWriter writer = ...) {\n    ...\n} catch (CassandraConnectorException e) {\n    if (e.getCode() == CLOSE_CQL_SESSION_FAILED) {\n        log.warn(\"Session close failed after flush; data already flushed\", e);\n    } else {\n        throw e;\n    }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// safe to downgrade: flush already completed before close\ntry {\n    writer.close();\n} catch (CassandraConnectorException e) {\n    if (CassandraConnectorErrorCode.CLOSE_CQL_SESSION_FAILED.equals(e.getErrorCode())) {\n        log.warn(\"ignoring session close failure after successful flush\");\n    } else { throw e; }\n}","preventionTips":["Ensure async writes complete before close (await completionStages).","Monitor Cassandra node health so sessions stay alive through job shutdown.","Treat this error as non-fatal when checkpoint/flush succeeded."],"tags":["cassandra","resource-cleanup","connection"],"backgroundTag":"connection-refused","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"}