PHP error guide
SQLSTATE HY000 lock wait timeout: meaning and fix
Error summary
Shorten transactions, lock rows consistently, and retry the whole idempotent transaction. A transaction waits longer than innodb_lock_wait_timeout for a conflicting lock.
What it means
Shorten transactions, lock rows consistently, and retry the whole idempotent transaction. A transaction waits longer than innodb_lock_wait_timeout for a conflicting lock.
What the error means
This message means that a transaction waits longer than innodb_lock_wait_timeout for a conflicting lock. The exact signature distinguishes sqlstate hy000 lock wait timeout from a generic application failure.
Why PHP produces it
The engine or service reports “SQLSTATE HY000 lock wait timeout” because its required precondition was not met. Shorten transactions, lock rows consistently, and retry the whole idempotent transaction.
PHP version notes
The sqlstate hy000 lock wait timeout wording here is based on PDO with MySQL/MariaDB; exact server wording varies; punctuation and exception class names can differ on older branches or vendor builds.
Most common causes
- The immediate input or configuration reaches the specific condition: a transaction waits longer than innodb_lock_wait_timeout for a conflicting lock
- The code path assumes the prerequisite for sqlstate hy000 lock wait timeout has already been satisfied.
- For sqlstate hy000 lock wait timeout, development and production differ in version, extension, permissions, paths, or service configuration.
- An earlier operation returned an unchecked value that is consumed by the line reporting sqlstate hy000 lock wait timeout.
Minimal examples
BAD — reproduces the problem
$pdo->beginTransaction();
updateA();
sleep(60);
$pdo->commit();
FIXED — safer pattern
$pdo->beginTransaction();
updateA();
$pdo->commit();
Step-by-step diagnosis
- Copy the complete “SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction” text and retain the first application stack frame.
- Reproduce sqlstate hy000 lock wait timeout in the same SAPI and environment listed for this page.
- Before changing sqlstate hy000 lock wait timeout, inspect the preceding value or directive and verify its type, path, version, and permissions.
- Apply the narrow correction—shorten transactions, lock rows consistently, and retry the whole idempotent transaction—then repeat the original request once.
Fixes
Correct the failing prerequisite
Shorten transactions, lock rows consistently, and retry the whole idempotent transaction
$pdo->beginTransaction();
updateA();
$pdo->commit();
Fail explicitly at the boundary
Validate the condition before the operation that emits sqlstate hy000 lock wait timeout, and log a safe diagnostic without credentials or full production paths.
Common mistakes when fixing it
- Suppressing sqlstate hy000 lock wait timeout instead of correcting its upstream condition.
- Testing sqlstate hy000 lock wait timeout only with the CLI binary when the failing request runs under FPM or Apache.
- Changing a global setting for sqlstate hy000 lock wait timeout before confirming the site-specific effective configuration.
How to prevent it
- Add a focused test that exercises the boundary responsible for sqlstate hy000 lock wait timeout.
- Keep runtime versions, extensions, configuration, and deploy artifacts affecting sqlstate hy000 lock wait timeout reproducible.
- Validate external data and service return values before they can trigger sqlstate hy000 lock wait timeout.
Web server / environment notes
fpm, cli, docker, linux. The failure occurs where a transaction waits longer than innodb_lock_wait_timeout for a conflicting lock
Tags: fpm,cli,docker,linux