{"record":{"id":"7f5da3db44d31e67","repo":"apache/flink","slug":"exception-in-close","errorCode":null,"errorMessage":"Exception in close","messagePattern":"Exception in close","errorType":"exception","errorClass":"TableException","httpStatus":null,"severity":"error","filePath":"flink-connectors/flink-connector-files/src/main/java/org/apache/flink/connector/file/table/FileSystemOutputFormat.java","lineNumber":217,"sourceCode":"    }\n\n    @Override\n    public void writeRecord(T record) {\n        try {\n            writer.write(record);\n        } catch (Exception e) {\n            throw new TableException(\"Exception in writeRecord\", e);\n        }\n    }\n\n    @Override\n    public void close() throws IOException {\n        try {\n            if (writer != null) {\n                writer.close();\n            }\n        } catch (Exception e) {\n            throw new TableException(\"Exception in close\", e);\n        }\n    }\n\n    /** Builder to build {@link FileSystemOutputFormat}. */\n    public static class Builder<T> {\n\n        private String[] partitionColumns;\n        private OutputFormatFactory<T> formatFactory;\n        private TableMetaStoreFactory metaStoreFactory;\n        private Path stagingPath;\n\n        private LinkedHashMap<String, String> staticPartitions = new LinkedHashMap<>();\n        private boolean dynamicGrouped = false;\n        private boolean overwrite = false;\n        private boolean isToLocal = false;\n        private FileSystemFactory fileSystemFactory = FileSystem::get;\n\n        private PartitionComputer<T> computer;","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-connectors/flink-connector-files/src/main/java/org/apache/flink/connector/file/table/FileSystemOutputFormat.java#L199-L235","documentation":"FileSystemOutputFormat.close closes the internal PartitionWriter if it is not null. Any exception during writer close (finalizing part files, flushing buffers, renaming temp files to final names) is caught and re-thrown as a TableException with message 'Exception in close'. This is the finalization step for each subtask.","triggerScenarios":"The PartitionWriter.close call fails: file system rename of part files from temporary to final names fails, final flush of buffered data encounters I/O error, or the format writer fails to finalize (e.g. Parquet footer write failure).","commonSituations":"File system rename failure (cross-filesystem rename on S3, HDFS safe mode). Parquet/ORC footer write failure due to corrupt internal state or I/O error. Output directory permissions changed mid-job. Disk full during final flush.","solutions":["Examine the chained cause of the TableException to find the specific close failure.","Verify file system health and that the output directory remains writable throughout the job lifecycle.","Check for disk space during the close phase (buffer flush + file finalization).","If using S3, be aware that rename operations may be copy-and-delete; ensure no throttling or timeout."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    outputFormat.close();\n} catch (TableException e) {\n    Throwable root = e.getCause();\n    // Close failure may leave partial files; investigate root cause\n    LOG.error(\"Output format close failed\", root);\n    throw e;\n}","preventionTips":["Ensure sufficient disk space for the final flush and file finalization.","Verify file system rename support (S3 may have copy-delete semantics).","Monitor file system health throughout the job lifecycle, not just at start.","For Parquet/ORC, ensure schema consistency to avoid footer write failures."],"tags":["output-format","close","partition-writer","table-exception","flink"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}