{"record":{"id":"938d78a9087c160b","repo":"alibaba/canal","slug":"received-error-packet-errno-sqlstate-e-938d78","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":"parse/src/main/java/com/alibaba/otter/canal/parse/inbound/mysql/dbsync/DirectLogFetcher.java","lineNumber":111,"sourceCode":"            final int mark = getUint8(NET_HEADER_SIZE);\n            if (mark != 0) {\n                if (mark == 255) // error from master\n                {\n                    // Indicates an error, for example trying to fetch from\n                    // wrong\n                    // binlog position.\n                    position = NET_HEADER_SIZE + 1;\n                    final int errno = getInt16();\n                    String sqlstate = forward(1).getFixString(SQLSTATE_LENGTH);\n                    String errmsg = getFixString(limit - position);\n                    if (StringUtils.containsIgnoreCase(errmsg, \"not find first log file name\")\n                        || StringUtils.containsIgnoreCase(errmsg, \"purged binary logs\")) {\n                        // 开始 dump 后，server 位点过期，DUMP 和 DUMP_GTID 两种错误信息\n                        throw new ServerLogPurgedException(\n                            \" errno = \" + errno + \", sqlstate = \" + sqlstate + \" errmsg = \" + errmsg);\n                    }\n\n                    throw new IOException(\"Received error packet:\" + \" errno = \" + errno + \", sqlstate = \" + sqlstate\n                                          + \" errmsg = \" + errmsg);\n                } else if (mark == 254) {\n                    // Indicates end of stream. It's not clear when this would\n                    // be sent.\n                    logger.warn(\"Received EOF packet from server, apparent\"\n                                + \" master disconnected. It's may be duplicate slaveId , check instance config\");\n                    return false;\n                } else {\n                    // Should not happen.\n                    throw new IOException(\"Unexpected response \" + mark + \" while fetching binlog: packet #\" + netnum\n                                          + \", len = \" + netlen);\n                }\n            }\n\n            // if mysql is in semi mode\n            if (issemi) {\n                // parse semi mark\n                int semimark = getUint8(NET_HEADER_SIZE + 1);","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/parse/src/main/java/com/alibaba/otter/canal/parse/inbound/mysql/dbsync/DirectLogFetcher.java#L93-L129","documentation":"Thrown as IOException('Received error packet') when the MySQL master returns error packet mark 255 during binlog streaming, but the error message does NOT match the 'purged logs' patterns of error 402. This is the catch-all for any non-purge replication error returned by the master while Canal is actively reading the binlog stream via DirectLogFetcher.fetch().","triggerScenarios":"The master replies with errno+sqlstate+errmsg after a DUMP request, but the errmsg is not about purged logs. Common MySQL errors: 1236 (fatal error reading binlog), 1227 (access denied for replication), 13114 (unable to read log event), or ER_* replication failures.","commonSituations":"The replication user lost REPLICATION SLAVE privilege mid-stream. The master's binlog file is corrupted. A failover occurred and the new master has a different server_id or binlog format. The requested position is beyond the end of the current binlog file. MySQL was upgraded and the binlog format changed.","solutions":["Read the errno and errmsg in the exception message to identify the specific MySQL error code.","For errno 1227: re-grant REPLICATION SLAVE, REPLICATION CLIENT privileges.","For errno 1236 with a non-purge message: check MySQL error log for binlog corruption; consider re-synchronizing from current master status.","Verify server_id uniqueness — duplicate server_id values cause the master to disconnect the slave stream."],"exampleFix":"// before — no specific handling\ntry {\n    directLogFetcher.fetch();\n} catch (IOException e) {\n    // generic handling\n}\n\n// after — distinguish replication errors\ntry {\n    directLogFetcher.fetch();\n} catch (ServerLogPurgedException e) {\n    // re-discover start position (handled by error 402 logic)\n} catch (IOException e) {\n    // inspect errno in message, retry with backoff or alert\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    directLogFetcher.fetch();\n} catch (IOException e) {\n    String msg = e.getMessage();\n    if (msg.contains(\"errno = 1227\")) {\n        // Access denied — privilege issue, do not retry blindly\n        throw new ConfigurationException(\"Replication privilege revoked mid-stream\", e);\n    } else if (msg.contains(\"errno = 1236\")) {\n        // Fatal binlog error — may need position reset\n        logger.error(\"Fatal binlog error from master\", e);\n    }\n    // Other errors: retry with backoff\n}","preventionTips":["Parse the errno from the exception message to determine the appropriate response.","Log the full errno/sqlstate/errmsg for post-mortem analysis.","Set up monitoring alerts for replication error packets to catch privilege revocations early."],"tags":["mysql","binlog","replication-error","io-exception"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}