Bug Report: ER_LOCK_NOWAIT (errno 3572) is reported as UNKNOWN
Overview of the Issue
MySQL returns ER_LOCK_NOWAIT (errno 3572, "Statement aborted because lock(s) could not be acquired immediately and NOWAIT is set.") when a locking read with NOWAIT can't get a lock right away. SQLError.VtRpcErrorCode in go/mysql/sqlerror/sql_error.go has no case for this errno, so vttablet reports it as UNKNOWN, both in the Errors counter and on the error returned to vtgate.
Applications that use NOWAIT expect this error. Because it's counted as UNKNOWN, it can't be told apart from real unknown errors in error-code metrics or alerts. vtgate also sends NOWAIT itself in foreign key plans for tables with unique keys.
The closest existing mapping is ER_LOCK_WAIT_TIMEOUT → DEADLINE_EXCEEDED. In both cases MySQL fails only the statement and leaves the transaction open. ABORTED, which ER_LOCK_DEADLOCK uses, would not fit. When vtgate sees ABORTED inside a transaction, it rolls back the whole transaction (ScatterConn.endAction → SafeSession.SetRollback), but after a NOWAIT failure MySQL has kept that transaction open.
Reproduction Steps
- Create a table:
create table t (id bigint primary key); insert into t values (1); - In session 1:
begin; select * from t where id = 1 for update; - In session 2:
begin; select * from t where id = 1 for update nowait; - Session 2 gets errno 3572, and vttablet's
Errorscounter goes up underUNKNOWN.
Binary Version
main (25.0.0-SNAPSHOT). The mapping is also missing in release-23.0 and release-24.0.Operating System and Environment details
Not environment-specific.Log Fragments
(errno 3572) (sqlstate HY000): Statement aborted because lock(s) could not be acquired immediately and NOWAIT is set.Source: vitessio/vitess