{"record":{"id":"78004331e2ad35e5","repo":"alibaba/canal","slug":"received-error-packet-errno-sqlstate-e","errorCode":null,"errorMessage":"Received error packet: errno = {}, sqlstate = {} errmsg = {}","messagePattern":"Received error packet: errno = (.+?), sqlstate = (.+?) errmsg = (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/DirectLogFetcher.java","lineNumber":307,"sourceCode":"            int netnum = getUint8(PACKET_SEQ_OFFSET);\r\n            if (!fetch0(NET_HEADER_SIZE, netlen)) {\r\n                logger.warn(\"Reached end of input stream: packet #\" + netnum + \", len = \" + netlen);\r\n                return false;\r\n            }\r\n\r\n            // Detecting error code.\r\n            final int mark = getUint8(NET_HEADER_SIZE);\r\n            if (mark != 0) {\r\n                if (mark == 255) // error from master\r\n                {\r\n                    // Indicates an error, for example trying to fetch from\r\n                    // wrong\r\n                    // binlog position.\r\n                    position = NET_HEADER_SIZE + 1;\r\n                    final int errno = getInt16();\r\n                    String sqlstate = forward(1).getFixString(SQLSTATE_LENGTH);\r\n                    String errmsg = getFixString(limit - position);\r\n                    throw new IOException(\"Received error packet:\" + \" errno = \" + errno + \", sqlstate = \" + sqlstate\r\n                                          + \" errmsg = \" + errmsg);\r\n                } else if (mark == 254) {\r\n                    // Indicates end of stream. It's not clear when this would\r\n                    // be sent.\r\n                    logger.warn(\"Received EOF packet from server, apparent\" + \" master disconnected.\");\r\n                    return false;\r\n                } else {\r\n                    // Should not happen.\r\n                    throw new IOException(\"Unexpected response \" + mark + \" while fetching binlog: packet #\" + netnum\r\n                                          + \", len = \" + netlen);\r\n                }\r\n            }\r\n\r\n            // The first packet is a multi-packet, concatenate the packets.\r\n            while (netlen == MAX_PACKET_LENGTH) {\r\n                if (!fetch0(0, NET_HEADER_SIZE)) {\r\n                    logger.warn(\"Reached end of input stream while fetching header\");\r\n                    return false;\r","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/DirectLogFetcher.java#L289-L325","documentation":"Thrown while reading a binlog dump packet from the master: the first payload byte (mark) was 255, which is MySQL's ERR packet marker. The library parses errno (2 bytes), skips 1 byte, reads the 5-char sqlstate, then the remaining errmsg, and raises IOException with all three. It is the master reporting a replication-request error, not a client-side bug.","triggerScenarios":"After sending COM_BINLOG_DUMP, the server replies with mark==255. Common server-side causes: the requested binlog file does not exist, the starting position is invalid/behind the master, the connecting user lacks REPLICATION SLAVE privilege, the server_id is 0 or collides, or binlogging is disabled on the master.","commonSituations":"Pointing at a wrong/non-existent binlog file name; requesting a position past the master's current one; a privileged proxy dropping REPLICATION SLAVE; server_id not configured; master restarted and rotated logs; reading from a replica that has no logs.","solutions":["Read errno/sqlstate/errmsg from the message and act on it: e.g. ER_ACCESS_DENIED_ERROR (1227) -> grant REPLICATION SLAVE; ER_MASTER_FATAL_ERROR_READING_BINLOG (1236) -> correct file/position.","SHOW MASTER STATUS on the source to obtain the current valid binlog file + position before open().","Ensure the connecting account has REPLICATION SLAVE (and REPLICATION CLIENT) privileges.","Set a unique non-zero server_id on the replicating client.","Confirm the master has log_bin enabled and the file name spelling matches exactly."],"exampleFix":"// before - guessing the file/position\nfetcher.open(conn, \"mysql-bin.000001\", 0L, serverId, false);\n\n// after - query the master for the real coordinates first\ntry (Statement s = conn.createStatement();\n     ResultSet rs = s.executeQuery(\"SHOW MASTER STATUS\")) {\n    rs.next();\n    String file = rs.getString(1);\n    long pos = rs.getLong(2);\n    fetcher.open(conn, file, pos, serverId, false);\n}","handlingStrategy":"retry","validationCode":"// Fetch authoritative coordinates and check privileges before dumping\ntry (Statement s = conn.createStatement();\n     ResultSet rs = s.executeQuery(\"SHOW MASTER STATUS\")) {\n    if (!rs.next()) throw new IOException(\"binlog disabled or no master status\");\n    String file = rs.getString(1); long pos = rs.getLong(2);\n    // pass file/pos to open()\n}","typeGuard":null,"tryCatchPattern":"try { fetcher.open(conn, file, pos, serverId, false); }\ncatch (IOException e) {\n    if (e.getMessage().startsWith(\"Received error packet:\")) {\n        // parse errno from message; on ER_MASTER_FATAL_ERROR_READING_BINLOG (1236) re-sync coordinates\n        logger.error(\"master rejected dump: \" + e.getMessage());\n        resyncCoordinatesAndRetry();\n    } else throw e;\n}","preventionTips":["Grant the replication user REPLICATION SLAVE + REPLICATION CLIENT.","Always obtain file/position from SHOW MASTER STATUS, never hard-code them.","Use a unique non-zero server_id per replicating client.","Re-resolve coordinates after a master restart."],"tags":["binlog","network","replication","mysql","privileges"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}