---
summary: Error 1213 "Deadlock found when trying to get lock" raised by COMMIT on a
  Galera cluster.
title: Deadlock at COMMIT
path: troubleshooting/deadlock-on-commit
status: published
---

# Deadlock at COMMIT

Your application reports `ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction`, and the statement that failed is `COMMIT`.

## Why it happens

Scuttle replicates synchronously and resolves write conflicts optimistically. When two transactions change the same rows at the same time, the one that commits second fails certification and is rolled back with a deadlock error. Nothing is wrong with the cluster, and no data was lost.

## Fix

Retry the whole transaction. The pattern and the list of retryable errors are in [Retrying transactions](/docs/scuttle/using/retries). Most ORMs and frameworks have a retry hook for `40001` serialization failures — enable it.

## If it happens often

Frequent conflicts mean many transactions compete for the same rows: a counter row, a queue table polled by many workers, or long transactions. Shorten the transactions, shard the hot row, or serialise that piece of work in the application.
