Skip to catalogue

184

deadlock

Two waiters each hold what the other needs. Nobody proceeds. Always take locks in one order.

What is deadlock?

A deadlock is a cycle of waits: A holds lock 1 and wants lock 2, B holds 2 and wants 1. Databases deadlock on row locks too. The cure is a global lock order, a timeout, or not holding a lock across a call.

Why does deadlock matter when vibe coding?

Models lock a row, call an HTTP API, then lock another row. Under load two requests invert the order. Name the order.

How do you do deadlock?

Acquire locks in a documented order. Do not call the network while holding a lock. Set a lock timeout so a cycle becomes an error you can retry, not a hang.

How do you ask a model for deadlock?

Avoid deadlock on (resources). Always acquire locks in (order). Do not hold a lock across a network call. Set a lock timeout and retry the transaction. Do not spawn a thread per request that waits on its sibling.

What goes wrong with deadlock?

Retrying a deadlock immediately forever. Back off. And fix the order, or the retry is the steady state.

adjacent