alibaba/canal · error · IOException
Query event length is too short.
Error message
Query event length is too short.
What it means
Thrown during construction of a QueryLogEvent when the buffer's total length (limit) is less than the sum of the common header length and post-header length. This means the event is too short to even contain its own header fields, indicating severe truncation or corruption.
Source
Thrown at dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/event/QueryLogEvent.java:413
boolean compatiablePercona) throws IOException{
this(header, buffer, descriptionEvent, compatiablePercona, false);
}
public QueryLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent,
boolean compatiablePercona,
boolean compress) throws IOException{
super(header);
this.compatiablePercona = compatiablePercona;
final int commonHeaderLen = descriptionEvent.commonHeaderLen;
final int postHeaderLen = descriptionEvent.postHeaderLen[header.type - 1];
/*
* We test if the event's length is sensible, and if so we compute
* data_len. We cannot rely on QUERY_HEADER_LEN here as it would not be
* format-tolerant. We use QUERY_HEADER_MINIMAL_LEN which is the same
* for 3.23, 4.0 & 5.0.
*/
if (buffer.limit() < (commonHeaderLen + postHeaderLen)) {
throw new IOException("Query event length is too short.");
}
int dataLen = buffer.limit() - (commonHeaderLen + postHeaderLen);
buffer.position(commonHeaderLen + Q_THREAD_ID_OFFSET);
sessionId = buffer.getUint32(); // Q_THREAD_ID_OFFSET
execTime = buffer.getUint32(); // Q_EXEC_TIME_OFFSET
// TODO: add a check of all *_len vars
final int dbLen = buffer.getUint8(); // Q_DB_LEN_OFFSET
errorCode = buffer.getUint16(); // Q_ERR_CODE_OFFSET
/*
* 5.0 format starts here. Depending on the format, we may or not have
* affected/warnings etc The remaining post-header to be parsed has
* length:
*/
int statusVarsLen = 0;
if (postHeaderLen > QUERY_HEADER_MINIMAL_LEN) {View on GitHub (pinned to 87be50e876)
Solutions
- Verify the FormatDescriptionLogEvent used for parsing has the correct postHeaderLen values for the server's binlog format version.
- Check buffer.limit() against the event's declared event-len to detect truncation.
- Ensure network reliability between replicator and MySQL server (timeouts, reconnect handling).
- Re-synchronize from a known-good binlog position if the event is genuinely truncated.
Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate buffer size against expected header size
int commonHeaderLen = descriptionEvent.commonHeaderLen;
int postHeaderLen = descriptionEvent.postHeaderLen[header.type - 1];
if (buffer.limit() < commonHeaderLen + postHeaderLen) {
logger.warn("Query event too short: limit={} < header={}", buffer.limit(), commonHeaderLen + postHeaderLen);
return; // or throw domain exception
} Try / catch
try {
QueryLogEvent event = new QueryLogEvent(header, buffer, descriptionEvent, compatiablePercona, compress);
} catch (IOException e) {
if (e.getMessage().contains("too short")) {
logger.warn("Truncated QueryLogEvent in binlog, skipping");
}
throw e;
} Prevention
- Verify the FormatDescriptionLogEvent's postHeaderLen table matches the MySQL server's binlog format.
- Monitor replication network health for partial event reads.
- Check buffer.limit() against the event header's event-len field before parsing.
When it happens
Trigger: Constructing QueryLogEvent from a binlog buffer. The commonHeaderLen and postHeaderLen come from the FormatDescriptionLogEvent. If buffer.limit() < commonHeaderLen + postHeaderLen, the event cannot be parsed and the exception fires.
Common situations: Truncated binlog event from a network interruption during replication, a corrupt binlog file, mismatched FormatDescriptionLogEvent (wrong postHeaderLen table), or the buffer was sliced incorrectly so limit is too small.
Related errors
- Format Description event header length is too short
- status_vars_len ( ) > data_len ( )
- No such method: '{}' @ {}
- No such field: '{}' @ {}
- Unable to unwrap {} to com.mysql.jdbc.ConnectionImpl
AI-assisted analysis of alibaba/canal@87be50e876 (2026-08-14).
Data as JSON: /api/errors/a398823c22051a42.
Report an issue: GitHub.