await-race
An asynchronous function writes a shared value from a read it made before an await.
- Group
- Code
- Runs
- On by default
- Level
- warning
- Reads
- Every file
- Fix
- None: whether to read the value again, claim it first, or move the
awaitdepends on what the function means to do
Why
An asynchronous function reads a module-level variable or a field of this or self, waits at an await, and then writes the value from that read or under a condition on it. Another task runs while the function waits and can change the value, so the write loses that task's update, as two withdrawals can both pass a balance check. Read the value again after the await, claim it before waiting, as by setting a flag, or keep the read and the write on the same side of the await. Ur takes every asynchronous function to be called concurrently, so each finding lists that assumption.
The fix, as Ur suggests it: read the value again after the await.
For agents
Never write shared state after an await from a value read before it; read it again after the await.
Example
src/account.tsexport class Account {
balance = 0;
async withdraw(amount: number): Promise<void> {
if (this.balance >= amount) {
await audit(amount);
this.balance -= amount;
}
}
}
declare function audit(amount: number): Promise<void>;
$ ur lint --rule await-race
warning[await-race]: `this.balance` is written from a value read before an `await`, and another task can change it while `withdraw` waits
--> ./src/account.ts:7:7 function `withdraw`
= step 1: ./src/account.ts:5:9 `this.balance` is read here
= step 2: ./src/account.ts:6:7 the function waits here, and another task can run
= step 3: ./src/account.ts:7:7 `this.balance` is written here from the earlier read
= assumes: concurrent-tasks
= hint: read the value again after the `await`
= see: asyncio, Synchronization Primitives, Python Software Foundation, Python 3.14 documentation (2025-10-07), https://docs.python.org/3.14/library/asyncio-sync.html
0 clone classes and 1 concurrency finding in 1 file
Source
asyncio, Synchronization Primitives, Python Software Foundation, Python 3.14 documentation (2025-10-07).