{"record":{"id":"c2d1c1822e345ee7","repo":"vitessio/vitess","slug":"first-event-from-binlog-v-is-not-valid","errorCode":null,"errorMessage":"first event from binlog %v is not valid","messagePattern":"first event from binlog (.+?) is not valid","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/binlog/binlog_connection.go","lineNumber":282,"sourceCode":"\tif err != nil {\n\t\treturn 0, err\n\t}\n\tdefer conn.Close()\n\n\tif err := conn.WriteComBinlogDump(bc.serverID, filename, 4, 0); err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to send the ComBinlogDump command: %v\", err)\n\t}\n\n\t// Get the first event to get its timestamp. We skip\n\t// events that don't have timestamps (although it seems\n\t// most do anyway).\n\tfor {\n\t\tevent, err := conn.ReadBinlogEvent()\n\t\tif err != nil {\n\t\t\treturn 0, fmt.Errorf(\"error reading binlog event %v: %v\", filename, err)\n\t\t}\n\t\tif !event.IsValid() {\n\t\t\treturn 0, fmt.Errorf(\"first event from binlog %v is not valid\", filename)\n\t\t}\n\t\tif ts := event.Timestamp(); ts > 0 {\n\t\t\treturn int64(ts), nil\n\t\t}\n\t}\n}\n\n// Close closes the binlog connection, which also signals an ongoing dump\n// started with StartBinlogDump() to stop and close its BinlogEvent channel.\n// The ID for the binlog connection is recycled back into the pool.\nfunc (bc *BinlogConnection) Close() {\n\tif bc.Conn != nil {\n\t\tlog.Info(\"closing binlog socket to unblock reads\")\n\t\tbc.Conn.Close()\n\n\t\t// bc.cancel is set at the beginning of the StartBinlogDump*\n\t\t// methods. If we error out before then, it's nil.\n\t\t// Note we also may error out before adding 1 to bc.wg,","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/binlog/binlog_connection.go#L264-L300","documentation":"After sending ComBinlogDump for a candidate file, getBinlogTimeStamp validates that the very first event returned is a valid binlog event (event.IsValid()). If it is not, the file's stream cannot be trusted to find a timestamp, and this error naming the file is returned. This usually indicates the file is truncated, not a real binlog, or the server sent something unexpected.","triggerScenarios":"getBinlogTimeStamp reads a first event that fails IsValid() — typically a zero-length/garbage first packet from a truncated or partially purged binlog file, or a server-side error delivered as a non-event packet.","commonSituations":"Binlog files truncated by a primary crash; manual copying/rsyncing of binlogs producing incomplete files; version-mismatched replica reading binlogs written by an incompatible server; relay-style proxies injecting unexpected frames.","solutions":["Verify the named file's integrity on the primary with mysqlbinlog; if truncated, stop serving it (or restore from backup).","Ensure the Vitess binary and MySQL server versions are compatible for replication protocol parsing.","Let findFileBeforeTimestamp proceed to an older intact binlog file if the requested timestamp allows it.","Check binlog_expire_logs_seconds / PURGE BINARY LOGS activity so files are not being removed or truncated during the scan."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// verify file integrity before probing\n// mysqlbinlog binlog.000123 > /dev/null && echo OK || echo CORRUPT","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"is not valid\") {\n\t// fall back to the next older binlog file, or re-seed from a backup\n}","preventionTips":["Enable binlog checksums and verify files after any crash recovery.","Don't truncate or partially copy binlogs during storage moves.","Watch binlog expiration so files aren't purged mid-scan.","Keep replica Vitess/MySQL versions in supported combinations."],"tags":["mysql","replication","binlog","corruption"],"backgroundTag":"invalid-binlog-event","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}