[MDEV-17541] KILL QUERY during lock wait in FOREIGN KEY check causes hang Created: 2018-10-24 Updated: 2019-01-29 Resolved: 2018-10-25 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Storage Engine - InnoDB, Storage Engine - XtraDB |
| Affects Version/s: | 10.2, 10.3 |
| Fix Version/s: | 10.3.11, 10.2.19 |
| Type: | Bug | Priority: | Blocker |
| Reporter: | Marko Mäkelä | Assignee: | Marko Mäkelä |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | crash, foreign-keys, kill, lock | ||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Description |
|
Bug #28068293 KILLING QUERY THAT IS WAITING FOR LOCK VIA FOREIGN KEY CAUSES MYSQL CRASH because a hard error code is being overwritten by the soft error DB_LOCK_WAIT. In MariaDB, the code is different because of Here is the signalling path from KILL QUERY that would cause lock_wait_suspend_thread() to abort the wait:
Here is a partial stack trace of the blocked thread:
The return value from row_ins_check_foreign_constraint() would propagate up the call stack all the way to row_ins(), which does some special handling for some error codes related to foreign keys and duplicate keys, and ultimately to this code in row_ins_step():
So, here we could be overwriting trx->error_state with the soft error DB_LOCK_WAIT. The caller row_insert_for_mysql() would then decide what to do:
In case of DB_LOCK_WAIT, row_mysql_handle_errors() would invoke lock_wait_suspend_thread() again. It would return immediately due to thr->state == QUE_THR_RUNNING. Finally, we would invoke row_ins_step() again, and we would get stuck in lock_wait_suspend_thread() until the wait is terminated by the savior thread:
Alas, we would again return DB_LOCK_WAIT, and again row_insert_for_mysql() would call row_ins_step() to retry the insert. The server would still be able to shut down. It looks like only way to end the infinite loop in the INSERT thread is to shut down the server. Here is the test case:
|
| Comments |
| Comment by Marko Mäkelä [ 2018-10-25 ] |
|
This regression in row_ins_check_foreign_constraint() was introduced in MySQL 5.7.8 and merged to MariaDB Server 10.2.2. |
| Comment by Vincent Milum Jr [ 2018-11-28 ] |
|
Is it possible that this bug either fixes, or is at least closely related to the "query end" never ends bug? The timelines match up well for when I first saw that issue, and symptoms seems closely related. |