{"record":{"id":"11ce2c024644acf0","repo":"alibaba/canal","slug":"no-binlog-file-header","errorCode":null,"errorMessage":"No binlog file header","messagePattern":"No binlog file header","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/FileLogFetcher.java","lineNumber":79,"sourceCode":"        open(new File(filePath), 0L);\r\n    }\r\n\r\n    /**\r\n     * Open binlog file in local disk to fetch.\r\n     */\r\n    public void open(String filePath, final long filePosition) throws FileNotFoundException, IOException {\r\n        open(new File(filePath), filePosition);\r\n    }\r\n\r\n    /**\r\n     * Open binlog file in local disk to fetch.\r\n     */\r\n    public void open(File file, final long filePosition) throws FileNotFoundException, IOException {\r\n        fin = new FileInputStream(file);\r\n\r\n        ensureCapacity(BIN_LOG_HEADER_SIZE);\r\n        if (BIN_LOG_HEADER_SIZE != fin.read(buffer, 0, BIN_LOG_HEADER_SIZE)) {\r\n            throw new IOException(\"No binlog file header\");\r\n        }\r\n\r\n        if (buffer[0] != BINLOG_MAGIC[0] || buffer[1] != BINLOG_MAGIC[1] || buffer[2] != BINLOG_MAGIC[2]\r\n            || buffer[3] != BINLOG_MAGIC[3]) {\r\n            throw new IOException(\"Error binlog file header: \"\r\n                                  + Arrays.toString(Arrays.copyOf(buffer, BIN_LOG_HEADER_SIZE)));\r\n        }\r\n\r\n        limit = 0;\r\n        origin = 0;\r\n        position = 0;\r\n\r\n        if (filePosition > BIN_LOG_HEADER_SIZE) {\r\n            final int maxFormatDescriptionEventLen = FormatDescriptionLogEvent.LOG_EVENT_MINIMAL_HEADER_LEN\r\n                                                     + FormatDescriptionLogEvent.ST_COMMON_HEADER_LEN_OFFSET\r\n                                                     + LogEvent.ENUM_END_EVENT + LogEvent.BINLOG_CHECKSUM_ALG_DESC_LEN\r\n                                                     + LogEvent.CHECKSUM_CRC32_SIGNATURE_LEN;\r\n\r","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/FileLogFetcher.java#L61-L97","documentation":"Thrown by FileLogFetcher.open() when reading the first BIN_LOG_HEADER_SIZE (4) bytes of a local binlog file returns fewer bytes than requested (or -1/EOF). The file is too short to even contain a binlog magic header, so it cannot be a valid binlog.","triggerScenarios":"new FileInputStream(file).read(buffer, 0, 4) returns a value != 4: the file is empty, < 4 bytes, or at EOF (the path points to an empty/partial file).","commonSituations":"Pointing at an empty file, a still-being-written/partial binlog, a rotated/renamed file, a directory or a non-binlog path, or a file truncated by disk-full / crash.","solutions":["Confirm the file path and that the file size is at least 4 bytes (and realistically >= the binlog header).","Verify the file is a complete binlog produced by mysqld (ls -l, file size > 0), not a temp/partial file.","Re-copy or re-fetch the binlog file from the master if it was truncated in transfer.","Point FileLogFetcher at a fully flushed, closed binlog rather than the live one mysqld is writing."],"exampleFix":"// before - opening whatever path was given\nfetcher.open(new File(path), filePosition); // < 4 bytes -> No binlog file header\n\n// after - sanity-check size first\nFile f = new File(path);\nif (!f.isFile() || f.length() < 4) {\n    throw new IOException(\"Not a binlog file (too short): \" + f);\n}\nfetcher.open(f, filePosition);","handlingStrategy":"validation","validationCode":"// Reject files too short to be binlogs before opening\nFile f = new File(path);\nif (!f.isFile() || f.length() < 4) {\n    throw new IOException(\"not a binlog (too short/missing): \" + f);\n}","typeGuard":null,"tryCatchPattern":"try { fetcher.open(new File(path), pos); }\ncatch (IOException e) {\n    if (e.getMessage().equals(\"No binlog file header\"))\n        throw new IOException(\"file is empty/truncated: \" + path, e);\n    throw e;\n}","preventionTips":["Check file size >= 4 (realistically >= the header) before open().","Open only fully written/closed binlog files, not the live one.","Verify the path resolves to a real file, not a directory."],"tags":["binlog","file","filelogfetcher","validation"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}