go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly
https://gorm.io
MIT License
36.92k stars 3.93k forks source link

updates report an error: Lock wait timeout exceeded; try restarting transaction #7199

Closed ycyxuehan closed 2 weeks ago

ycyxuehan commented 1 month ago

libs: gorm.io/driver/mysql v1.5.6 gorm.io/gorm v1.25.10 gorm.io/plugin/dbresolver v1.5.2 go: 1.21 mysql: 8.0 dbconfigs: showLog: true maxLifeTime: 30 maxIdleTime: 30 maxOpenConnections: 1024 maxIdleConnections: 100

code: err := c.db.Table(tablename).Where("u= ? AND bbb IN ? AND t = ?", u, bbb, t).Updates(updateCols).Error

Error 1205 (HY000): Lock wait timeout exceeded; try restarting transaction [51664.069ms] [rows:0] UPDATE aaaa SET enabled=false WHERE u = 1 AND bbb IN (1) AND t = 0;

but i use mysql client execut it in console, it success and very fast:

Query OK, 0 rows affected (0.00 sec) Rows matched: 0 Changed: 0 Warnings: 0

in this time, not all update failed, only the updates call failed.

github-actions[bot] commented 1 month ago

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

ycyxuehan commented 1 month ago

libs: gorm.io/driver/mysql v1.5.6

gorm.io/gorm v1.25.10 gorm.io/plugin/dbresolver v1.5.2 go: 1.21 mysql: 8.0 dbconfigs: showLog: true maxLifeTime: 30 maxIdleTime: 30 maxOpenConnections: 1024 maxIdleConnections: 100 code: err := c.db.Table(tablename).Where("u= ? AND bbb IN ? AND t = ?", u, bbb, t).Updates(updateCols).Error

Error 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

[51664.069ms] [rows:0] UPDATE aaaa SET enabled=false WHERE u = 1 AND bbb IN (1) AND t = 0; but i use mysql client execut it in console, it success and very fast:

Query OK, 0 rows affected (0.00 sec)

Rows matched: 0 Changed: 0 Warnings: 0 in this time, not all update failed, only the updates call failed.

when i remove the slave codes, this error disappeared

github-actions[bot] commented 1 month ago

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking