[5.x]: Product save causes long-running queries leading to minutes-long hangs

未关闭
#4,264 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
冷清
技术栈
mariadb, mysql, php

调研方向

首先重现远程 Commerce 产品保存操作,并检查 elements/apply-draft 请求。跟踪 GET_LOCK() 周围的 Product::afterPropagate()、Revisions::createRevision() 和 MysqlMutex,同时比较 MySQL 与 MariaDB 中 SHOW FULL PROCESSLIST 里的卡住的 elements SELECT。完成的标准是找出原因,并验证保存操作能够按预期完成,不会出现长时间运行的查询或 Server has gone away 错误。

由索引模型根据 Issue 内容生成。

描述

bug commerce5 Craft Commerce
What happened?
Description

On our staging/production environment, saving a Commerce product from the control panel can take many minutes, the CP appears to hang, and the front of the site is hard to reach while the save is in progress. In the queue we see jobs such as “Generating catalog pricing” and “Updating search indexes”, but profiling suggests the real bottleneck is long-running MySQL work, not those jobs completing slowly in isolation.

On local (DDEV) with the same project, product saves complete in a reasonable time.

We traced two concrete failure modes:

  1. SQLSTATE[HY000]: General error: 2006 Server has gone away during elements/apply-draft. The stack shows the failure when acquiring a DB mutex / revision work (GET_LOCK via MysqlMutex) after Product::afterPropagate() → Revisions::createRevision(), consistent with the DB connection being dropped mid-request (e.g. server wait_timeout vs a very long apply/save).

  2. SHOW FULL PROCESSLIST repeatedly shows the same SELECT on elements (columns such as id, canonicalId, fieldLayoutId, uid, …) stuck in Statistics for hundreds to thousands of seconds. Several such connections can pile up at once.

We have used KILL on stuck connections. Local DB is MySQL 8; server is MariaDB 10.6, so optimizer behavior may differ from dev even with identical code.

We have some fields coming from plugins in the products, so I tried to remove them, but still no luck. We don't have a lot of products and variants (~75 total).

I've seen others issues like this one but we still have the problem. Everything is up to date.

Steps to reproduce
  1. Open the control panel on a remote environment.
  2. Edit a Commerce product.
  3. Click Save.
  4. CP and site are now stuck.
Expected behavior

Product save should complete in a short, predictable time, without blocking the site for minutes, and without MySQL sessions stuck during normal saves.

Actual behavior
  • Save take minutes; CP and site feel blocked for other users.
  • DB may show multiple long-lived SELECT … elements … queries in Statistics, or 2006 Server has gone away during apply-draft / revision-related steps.
Craft CMS version

5.9.17

Craft Commerce version

5.6.1

PHP version

8.2.30

Operating system and version

Linux 4.18.0-553.89.1.lve.el8.x86_64

Database type and version

MariaDB 10.6.24

Image driver and version

GD 8.2.30

Installed plugins and versions
  • CKEditor 5.3.1
  • Neo 5.5.7
  • SEO 5.0.0
  • Moneris for Craft Commerce 1.0.0 (custom payment gateway by us)
主要语言
PHP
星标
242
派生
172
平均合并
21 小时 23 分钟
30 天内合并 PR
76

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

craftcms/commerce 的其他 Issue

查看 craftcms/commerce 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。