{"record":{"id":"d9d86d533eaa2964","repo":"apache/seatunnel","slug":"writer-operation-failed-d9d86d","errorCode":"WRITER_OPERATION_FAILED","errorMessage":"unable to close JDBC sink write","messagePattern":"unable to close JDBC sink write","errorType":"error_code","errorClass":"JdbcConnectorException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/sink/JdbcSinkWriter.java","lineNumber":363,"sourceCode":"                        throwAsIoException(e);\n                    }\n                    handleRowLevelBatchFailure(RowErrorPhase.CLOSE, null, batchRows, e);\n                } finally {\n                    outputFormat.close();\n                }\n            }\n            return;\n        }\n\n        tryOpen();\n        outputFormat.flush();\n        try {\n            Connection connection = connectionProvider.getConnection();\n            if (!connection.getAutoCommit()) {\n                connection.commit();\n            }\n        } catch (SQLException e) {\n            throw new JdbcConnectorException(\n                    CommonErrorCodeDeprecated.WRITER_OPERATION_FAILED,\n                    \"unable to close JDBC sink write\",\n                    e);\n        } finally {\n            outputFormat.close();\n        }\n    }\n\n    private void reportAndClearPendingRowsIfCommitted(boolean autoFlushed) throws IOException {\n        if (pendingRows == null) {\n            return;\n        }\n        if (autoFlushed) {\n            if (markSuccessfulAutoFlushBoundaryIfNeeded()) {\n                reportWriteSuccess(pendingRows);\n                pendingRows.clear();\n            }\n        }","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/sink/JdbcSinkWriter.java#L345-L381","documentation":"On close(), JdbcSinkWriter tries to commit any still-open transaction (when autoCommit is false) before releasing resources. If obtaining the connection or committing throws SQLException, it throws JdbcConnectorException with code WRITER_OPERATION_FAILED; outputFormat.close() still runs in the finally block. This indicates pending uncommitted data may be lost or the connection is already broken.","triggerScenarios":"Writer close at job end or on failure recovery: connectionProvider.getConnection() fails (pool exhausted, connection closed) or connection.commit() throws because the session was killed, network dropped, or the transaction was already rolled back server-side.","commonSituations":"Long-running jobs whose DB session timed out before close; DBA killed a long transaction; connection pool stale connections; abrupt network failures during job shutdown.","solutions":["Inspect the SQLException cause for connection-closed/session-killed errors and fix underlying timeout/network settings.","Enable connection pool validation queries and sensible idle timeouts so dead connections are evicted.","Rerun the job; data committed at earlier checkpoints is safe, uncommitted tail data must be re-read by the source.","If using XA/exactly-once, ensure recover transactions are cleaned up on the database."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// before close-sensitive work: check connection\nif (connection.isClosed()) { log.warn(\"connection already closed\"); }","typeGuard":null,"tryCatchPattern":"try {\n  writer.close();\n} catch (JdbcConnectorException e) {\n  if (e.getSeatunnelCode() == CommonErrorCodeDeprecated.WRITER_OPERATION_FAILED) {\n    // cause is SQLException: treat as connection loss, rerun job from checkpoint\n  }\n}","preventionTips":["Keep session timeouts longer than expected job duration","Avoid DBA-side session kills during job windows","Use validated/pooled connections to avoid stale sessions","Rerun from checkpoints; only tail data after last checkpoint is affected"],"tags":["jdbc","writer","connection","close"],"backgroundTag":"database-write-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}