SQL ServerPostgreSQLMySQL

"Lock request time out period exceeded" (Msg 1222)

Another session held a lock this one needed for longer than it was willing to wait. Unlike a deadlock, SQL Server doesn't resolve this for you — the blocking session keeps running, and you need to go find it yourself.

  • SQL Server: Msg 1222, Level 16, State 56 followed by Lock request time out period exceeded.
  • PostgreSQL: ERROR: canceling statement due to lock timeout (when lock_timeout is set — off by default, unlike SQL Server)
  • MySQL (InnoDB): ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

How this differs from a deadlock

A deadlock is two transactions stuck waiting on each other — SQL Server detects that cycle and breaks it automatically by rolling one of them back. This is simpler and SQL Server does nothing about it on its own: one session is just holding a lock, another session waited for it longer than its LOCK_TIMEOUT setting allows, and SQL Server cancels the waiting statement. The blocking transaction is not rolled back or even touched — it keeps running exactly as before.

Where the timeout comes from

LOCK_TIMEOUT is a session-level setting, in milliseconds, defaulting to -1 (wait forever) unless something set it explicitly:

SET LOCK_TIMEOUT 5000;  -- give up waiting after 5 seconds, this session only

If you're seeing Msg 1222 at all, some connection — your application's connection pool configuration, an ORM default, or an explicit SET — has this set to a finite value. Query the current session's setting with SELECT @@LOCK_TIMEOUT; (-1 means no timeout is active).

Finding what's actually holding the lock

The error tells you a statement gave up waiting — it doesn't tell you who it was waiting on. That's a separate lookup:

-- sessions currently blocked, and what's blocking them
SELECT
  blocking.session_id   AS blocking_session,
  blocked.session_id    AS blocked_session,
  waits.wait_type,
  waits.wait_duration_ms
FROM sys.dm_exec_requests AS blocked
JOIN sys.dm_exec_sessions AS blocking
  ON blocking.session_id = blocked.blocking_session_id
JOIN sys.dm_os_waiting_tasks AS waits
  ON waits.session_id = blocked.session_id
WHERE blocked.blocking_session_id <> 0;

A zero rows result here doesn't mean nothing happened — it means whatever was blocking already finished and released the lock by the time you ran this. Catching an active case requires querying while the timeout is actually happening, or capturing it after the fact via Extended Events (the blocked_process_report event, specifically built for this).

The fix depends on what you find

A long-running transaction holding locks it doesn't need to — the usual case: a transaction that does unrelated work (an API call, a report query, logging) between acquiring a lock and committing, holding that lock the entire time. Shrink the transaction to only what actually needs to be atomic.

An implicit transaction left open accidentally — SET IMPLICIT_TRANSACTIONS ON (or a tool/driver default that behaves the same way) means a SELECT can silently start a transaction that never gets committed until something explicitly does. Confirm @@TRANCOUNT is what you expect before assuming a query is read-only and side-effect-free.

Genuine contention under real load — multiple sessions legitimately all wanting the same row or page at once. Raising LOCK_TIMEOUT just delays the symptom; the actual fix is usually a narrower transaction scope or a different isolation level (READ COMMITTED SNAPSHOT removes most reader/writer blocking entirely, at the cost of tempdb overhead for row versioning).

Can't demonstrate this in the playground

Like a deadlock, this requires two concurrent sessions — one holding a lock, a separate one waiting on it past a timeout. The SQLite sandbox here is a single connection with nothing to block against. Reproduce it against SQL Server with a second session holding an uncommitted transaction on a row, and SET LOCK_TIMEOUT on the first short enough to observe it expire.

  • Transaction deadlock victim — the related error where SQL Server resolves the standoff itself instead of just giving up and erroring.
  • Transactions — BEGIN/COMMIT/ROLLBACK, and how long a transaction actually holds its locks.
  • NOLOCK risks — a common (and risky) way people try to dodge blocking entirely, and what it actually costs.