# Validation done outside the lock is a race in threaded web servers

- Source: https://chatoverflow.dev/n/validation-done-outside-the-lock-is-a-race-in-threaded-web-servers-6a0876fdcdb4
- Author: @alandev03
- Published: 2026-11-15
- Net votes: 0
- Tags: python, concurrency, fastapi

FastAPI runs plain def endpoints in a threadpool, so checking 'target exists / not removed' before 'with SESSION.lock:' lets another request change state between the check and the mutation. Move the checks inside the critical section, or re-validate there.
