{"record":{"id":"0ff01b34076fe24a","repo":"vitessio/vitess","slug":"error-reading-binlog-event-v-v","errorCode":null,"errorMessage":"error reading binlog event %v: %v","messagePattern":"error reading binlog event (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/binlog/binlog_connection.go","lineNumber":279,"sourceCode":"\nfunc (bc *BinlogConnection) getBinlogTimeStamp(filename string) (blTimestamp int64, err error) {\n\tconn, err := connectForReplication(bc.cp)\n\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","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/binlog/binlog_connection.go#L261-L297","documentation":"While probing a binlog file for its first event's timestamp, getBinlogTimeStamp calls conn.ReadBinlogEvent in a loop. A read failure (IO error, malformed packet, server disconnect) aborts the probe with this error, which includes both the binlog filename and the underlying error. It means the event stream from that file could not be read at all.","triggerScenarios":"getBinlogTimeStamp (via findFileBeforeTimestamp → StartBinlogDumpFromBinlogBeforeTimestamp) reads a corrupted/truncated binlog file, the server disconnects mid-event, or the packet stream is garbled by a proxy.","commonSituations":"Corrupted binlogs after a primary crash or disk issue; binlog files partially purged on disk; intervening proxies mangling raw replication protocol; MySQL killed mid-dump.","solutions":["Inspect the wrapped error: connection-closed implies retry/reconnect; protocol/packet errors imply binlog corruption.","If corruption is suspected, run mysqlbinlog --verify-binlog-checksum on the named file on the primary.","Reconnect and let findFileBeforeTimestamp continue with the next (older) candidate file if the current one is unusable.","Remove proxies from the replication path or configure them to pass raw TCP unchanged for replication connections."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// on the primary: verify the candidate file before streaming it\n// mysqlbinlog --verify-binlog-checksum /var/lib/mysql/binlog.000123","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"error reading binlog event\") {\n\t// treat as unreadable file: skip to next older binlog or re-sync via backup\n}","preventionTips":["Monitor disk health on primaries to prevent binlog corruption.","Never hand-copy binlog files with rsync/cp; use proper backup tooling.","Keep Vitess and MySQL protocol versions compatible.","Alert on server-side disconnects during replication."],"tags":["mysql","replication","binlog","corruption"],"backgroundTag":"binlog-event-read-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}