#21324·vitess

Bug Report: ER_LOCK_NOWAIT (errno 3572) is reported as UNKNOWN

Author: martinarrietaCreated Sep 30, 2026Updated Sep 30, 2026
LabelsType: BugComponent: Query Serving

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

  1. Create a table:
    sql
    create table t (id bigint primary key);
    insert into t values (1);
  2. In session 1:
    sql
    begin;
    select * from t where id = 1 for update;
  3. In session 2:
    sql
    begin;
    select * from t where id = 1 for update nowait;
  4. Session 2 gets errno 3572, and vttablet's Errors counter goes up under UNKNOWN.

Binary Version

bash
main (25.0.0-SNAPSHOT). The mapping is also missing in release-23.0 and release-24.0.

Operating System and Environment details

bash
Not environment-specific.

Log Fragments

bash
(errno 3572) (sqlstate HY000): Statement aborted because lock(s) could not be acquired immediately and NOWAIT is set.