背景
MySQL
集群
使用了中间件 mycat
但测试发现,替换了原来的数据连接后,会出现 Packets out of order
的报错同时注意到,有的框架代码中竟然也会失效,比如 controller 类中,获取
$request->all()
竟然变空了
分析、排查
mycat
后,程序报错的一段源码如下:[2024-07-04 10:48:58] local.ERROR: Packets out of order. Expected 1 received 5. Packet size=85 (SQL: select `cms_password_resets`.* where `memberid` = 122 and `cms_password_resets`.`deleted_at` is null order by `id` desc) at D:\\phpstudy_pro\\WWW\\projzqb1b\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php:664, ErrorException(code: 0): Packets out of order. Expected 1 received 5. Packet size=85 at D:\\phpstudy_pro\\WWW\\projzqb1b\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php:332)
[2024-07-04 16:14:53] local.ERROR: Allowed memory size of 268435456 bytes exhausted (tried to allocate 842087056 bytes) {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalErrorException(code: 1): Allowed memory size of 268435456 bytes exhausted (tried to allocate 842087056 bytes) at D:\\phpstudy_pro\\WWW\\projzqb1b\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php:330)
[stacktrace]
SQLSTATE[HY000]: General error: 1047 Unsupported statement
mysql.cnf
中的 max_allowed_packet
参数
但是,发现不应该是这个问题,毕竟不使用 mycat 时不会出现问题
database.php
中的 options
的预处理可以解决报错 (但是查询出来的数据全部转为了字符串
)
因为上述的变动,代码中的判断,可能会出现问题,尤其是一些 数字类型的
===
比对