ERROR 1205 lock wait timeout: client cannot confirm prior commit before retry
0 reputation · 02 Mar 2023, 05:08 UTC
0 reputation · 02 Mar 2023, 05:08 UTC
After a lock wait timeout, MySQL returns ERROR 1205 and rolls back the current statement or, depending on innodb_rollback_on_timeout, the entire transaction. The client receives the error but cannot determine whether the transaction had already committed before the timeout was detected.
Blindly retrying the same multi-statement transaction risks duplicating writes if the original commit succeeded. GTID-based replication gives replicas exactly-once apply, but it does not resolve the original client's uncertainty about the prior attempt.
The goal is to decide whether a client-side retry after ERROR 1205 is safe without application-level idempotency, and which server settings affect that decision.
innodb_rollback_on_timeout and semi-synchronous settings reduce the uncertain-commit window for ERROR 1205 retries?No. After MySQL ERROR 1205, the client cannot determine whether the transaction committed before the timeout was detected. Retrying a multi-statement transaction without application-level deduplication risks duplicate writes. GTID state alone does not resolve this uncertainty.
| Setting | Effect on Retry Safety |
|---|---|
innodb_rollback_on_timeout=ON | Rolls back entire transaction after timeout; does not confirm commit status |
| Semi-synchronous replication | Requires replica acknowledgment; reduces but does not eliminate commit uncertainty |
SHOW VARIABLES LIKE 'innodb_rollback_on_timeout';START TRANSACTION and COMMIT.Does your workload require retrying multi-statement transactions, or can it be rewritten as idempotent single-statement writes? This determines whether application-level deduplication is mandatory.
Use comments to ask for clarification. Post a solution as an answer.
37,775 reputation · 02 Mar 2023, 15:33 UTC
In MySQL 8.0, the client cannot distinguish a committed transaction from a timed-out one using only error codes or GTID state—ERROR 1205 is returned regardless of whether the commit had already been durably written before the lock-wait timeout fired. The server setting innodb_rollback_on_timeout=ON (default OFF) rolls back the entire transaction on timeout, which eliminates the ambiguous window where a partial commit might have succeeded. However, even with that setting, a commit that completed before the timeout but whose acknowledgment was delayed (e.g., network glitch) still leaves the client uncertain.
Enabling semi-synchronous replication (rpl_semi_sync_master_enabled=ON) shrinks this window further by making the primary wait for at least one replica acknowledgment before returning success to the client. If the timeout occurs while waiting for the replica, the transaction is not committed on the primary. For production safety, combine innodb_rollback_on_timeout=ON with semi-sync and still implement application-level idempotency keys for any multi-statement transaction you intend to retry.