已关闭
[Bug]: mysql客户端发送大包报错 #1622
superlchf创建于  8月25日关闭于  29 天前
superlchf成员
8月25日 创建

测试类型

SQL功能

测试版本

7.0.0-RC3

问题描述

mysql客户端发送大包报错

操作系统和硬件信息

Linux oepnGauss177 6.6.0-95.0.0.99.oe2403sp164kb.aarch64 #1 SMP Mon Jun 9 11:44:02 CST 2025 aarch64 aarch64 aarch64 GNU/Linu

测试环境

企业版单机

被测功能

预置条件

操作步骤

1. 安装客户端

系统没有 MySQL CLI 时,可以安装 PyMySQL:

python3 -m pip install --user PyMySQL

PyMySQL 的 _execute_command() 会根据 MAX_PACKET_LEN=0xFFFFFF 自动分包,属于真实
MySQL wire protocol 测试,不是模拟 SQL 大小。

2 确认 PyMySQL 分包实现

可以执行:

python3 - <<'PY'
import inspect
import pymysql.connections

print("MAX_PACKET_LEN =", pymysql.connections.MAX_PACKET_LEN)
print(inspect.getsource(pymysql.connections.Connection._execute_command))
PY

预期看到:

MAX_PACKET_LEN = 16777215

以及循环调用 write_packet() 发送剩余 SQL 的逻辑。

3 完整测试脚本

以下脚本先发送 1 MB 单 payload 对照请求,再使用新连接发送 17 MB 多 payload 请求。

python3 - <<'PY'
import time
import pymysql

HOST = "127.0.0.1"
PORT = 3308
USER = "test"
PASSWORD = "PlainPass123"
DATABASE = "test_b"


def connect():
    return pymysql.connect(
        host=HOST,
        port=PORT,
        user=USER,
        password=PASSWORD,
        database=DATABASE,
        charset="utf8mb4",
        autocommit=True,
        connect_timeout=10,
        read_timeout=60,
        write_timeout=60,
    )


# 1. 建表并验证 1 MB 单 payload 请求。
connection = connect()
with connection.cursor() as cursor:
    cursor.execute("DROP TABLE IF EXISTS mysql_packet_test")
    cursor.execute(
        "CREATE TABLE mysql_packet_test ("
        "id INT AUTO_INCREMENT PRIMARY KEY, "
        "payload LONGTEXT)"
    )

    small_payload = "x" * 1_000_000
    small_query = (
        "INSERT INTO mysql_packet_test(payload) VALUES ('"
        + small_payload
        + "')"
    )
    print("small query bytes:", len(small_query.encode("utf-8")))
    cursor.execute(small_query)
    cursor.execute(
        "SELECT LENGTH(payload) "
        "FROM mysql_packet_test ORDER BY id DESC LIMIT 1"
    )
    print("stored small length:", cursor.fetchone()[0])
connection.close()


# 2. 使用新连接发送约 17 MB 的 COM_QUERY。
connection = connect()
large_payload = "x" * 17_000_000
large_query = (
    "INSERT INTO mysql_packet_test(payload) VALUES ('"
    + large_payload
    + "')"
)

print("large query bytes:", len(large_query.encode("utf-8")))
print("logical payload bytes:", len(large_query.encode("utf-8")) + 1)
print("single payload max:", 0xFFFFFF)

started = time.monotonic()
try:
    with connection.cursor() as cursor:
        cursor.execute(large_query)
        print("insert result: SUCCESS")
        cursor.execute(
            "SELECT LENGTH(payload) "
            "FROM mysql_packet_test ORDER BY id DESC LIMIT 1"
        )
        print("stored large length:", cursor.fetchone()[0])
except Exception as exception:
    print("insert result: ERROR")
    print("exception type:", type(exception).__name__)
    print("exception args:", repr(exception.args))
    print("exception text:", str(exception))
finally:
    print("elapsed seconds:", round(time.monotonic() - started, 3))
    print("connection open flag:", connection.open)

try:
    connection.ping(reconnect=False)
    print("ping after large query: SUCCESS")
except Exception as exception:
    print("ping after large query: ERROR")
    print("ping exception:", type(exception).__name__, repr(exception.args))
finally:
    connection.close()


# 3. 使用新连接清理,避免复用可能已断开的连接。
cleanup_connection = connect()
with cleanup_connection.cursor() as cursor:
    cursor.execute("DROP TABLE IF EXISTS mysql_packet_test")
    cursor.execute("SELECT 1")
    print("cleanup connection query:", cursor.fetchone()[0])
cleanup_connection.close()
PY

预期输出

成功

实际输出

报错

日志信息

large query bytes: 17000050
logical payload bytes: 17000051
single payload max: 16777215
insert result: ERROR
exception type: InternalError
exception args: ('Packet sequence number wrong - got 1 expected 2',)
connection open flag: False
ping after large query: ERROR

提单组织

内部开发

测试代码

likedislike
Ssuperlchf成员
8月25日 添加了label:bug
opengauss_bot
opengauss_bot成员
8月25日 评论:

This issue requires an assignee. Since you haven't specified one, we've assigned TestManager as the default assignee for this issue.

likedislike
opengauss_botopengauss_bot成员
8月25日 将 TestManager 设为负责人
opengauss_botopengauss_bot成员
8月25日 添加了label:sig/Plugin
opengauss_bot
opengauss_bot成员
8月25日 评论:

Welcome To openGauss Community

Hey @superlchf , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands. You can self-configure the PR merge rules for this repository. For more details, please refer to Here.

Contact Guide

If you have any questions, please contact the SIG: Plugin ,
and any of the maintainers: @CarrotGo, @chendong76, @chenxiaobin19, @congzhou2603, @dodders, @hwworkholic, @jemappellehc, @muyulinzhong, @quemingjian, @shenzheng4, @shirley_zhengx, @superlchf, @totaj, @wlff234, @wofanzheng, @ywzq1161327784 ,
and any of the committers: @dreamalloc, @huyinghao, @libiao2024, @wangfeihuo, @wmy_ld, @wuyuechuan, @xiong_xjun, @zhangxubo, @zhaojunv3z810 .

likedislike
Ssuperlchf成员
8月25日 将 superlchf 设为负责人
Ssuperlchf成员
8月25日 移除了负责人 TestManager
Ssuperlchf成员
8月25日 关联了pull request:【bugfix】修复mysql客户端发送超大包问题
Ssuperlchf成员
8月25日 关联了pull request:[Bug回合6.0.0]: mysql客户端发送大包报错
sungang14sungang14成员
9月3日 关联了看板:openGauss 7.0.0-LTS
sungang14sungang14成员
9月3日 issue优先级由 无优先级 改变为 次要
ywzq1161327784ywzq1161327784成员
9月3日 issue状态由 待办的 改变为 已完成
Ssuperlchf成员
9月10日 issue状态由 已完成 改变为 待回归
superlchf成员
9月12日 评论:

用转测版本转测成功
image.png

likedislike
lijing3007kkk
lijing3007kkk成员
29 天前 评论:

回归结论:通过
回归版本:7.0.0-LTS b0023
回归截图:

image.png

likedislike
lijing3007kkklijing3007kkk成员
29 天前 issue状态由 待回归 改变为 已验收
lijing3007kkklijing3007kkk成员
29 天前 关闭了 issue