{"record":{"id":"12dd3c04c1cfaea3","repo":"apache/seatunnel","slug":"failed-to-close-dataset","errorCode":null,"errorMessage":"Failed to close dataset: {}","messagePattern":"Failed to close dataset: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-lance/src/main/java/org/apache/seatunnel/connectors/seatunnel/lance/sink/LanceSinkWriter.java","lineNumber":203,"sourceCode":"        flushBatch();\n        return Optional.empty();\n    }\n\n    @Override\n    public void abortPrepare() {\n        batchBuffer.clear();\n    }\n\n    @Override\n    public void close() throws IOException {\n        try {\n            flushBatch();\n        } finally {\n            if (dataset != null) {\n                try {\n                    dataset.close();\n                } catch (Exception e) {\n                    log.warn(\"Failed to close dataset: {}\", e.getMessage());\n                }\n                dataset = null;\n            }\n\n            if (allocator != null) {\n                try {\n                    allocator.close();\n                } catch (Exception e) {\n                    log.warn(\"Failed to close allocator: {}\", e.getMessage());\n                }\n                allocator = null;\n            }\n        }\n    }\n}\n","sourceCodeStart":185,"sourceCodeEnd":219,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-lance/src/main/java/org/apache/seatunnel/connectors/seatunnel/lance/sink/LanceSinkWriter.java#L185-L219","documentation":"LanceSinkWriter.close flushes pending batches and then closes the underlying Lance dataset. If dataset.close() throws (native/JNI resource release failure), the writer logs this warning with the exception message and continues cleanup (nulling the reference and closing the allocator). Data already flushed is unaffected, but the failure may indicate a leaked or corrupted native handle.","triggerScenarios":"Closing the sink writer when the Lance JNI dataset handle is already closed, corrupted, or the underlying object store transaction fails during close, after flushBatch has run.","commonSituations":"Double-close after a task failure/retry; JVM shutdown while native memory is pinned; transient storage backend errors during dataset teardown.","solutions":["Check the logged exception message for the root cause (often a JNI or storage error)","Ensure close() is not called twice on the same writer (task lifecycle guard)","Upgrade the lance JNI library if the message indicates a native crash or leak","Verify the storage backend (S3/OSS/local disk) is healthy and reachable at close time"],"exampleFix":"// before\nwriter.close();\nwriter.close(); // second close logs 'Failed to close dataset'\n// after\nif (!closed) {\n    writer.close();\n    closed = true;\n}","handlingStrategy":"try-catch","validationCode":"// guard against double close\nif (writerClosed) return;","typeGuard":null,"tryCatchPattern":"try { writer.close(); } catch (Exception e) { log.warn(\"Lance writer close issue: {}\", e.getMessage()); }","preventionTips":["Close each writer exactly once per task lifecycle","Ensure flush succeeds before interpreting close warnings as data loss","Monitor storage backend health at teardown"],"tags":["lance","sink","resource-cleanup","jni"],"backgroundTag":"resource-cleanup-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"}