Repository navigation
Description
π Reproduction steps
- Table with an
integercolumnn; rowawithn = 0. POST /v1/tablesdb/transactionswith{"ttl": 300}β transaction{transactionId}.POST /v1/tablesdb/transactions/{transactionId}/operationswith one operation:{"action": "increment", "databaseId": "{databaseId}", "tableId": "{tableId}", "rowId": "a", "data": {"column": "n", "value": 1}}.- Send
PATCH /v1/tablesdb/transactions/{transactionId}with{"commit": true}twice at the same time (for example a client retry after a timeout; tested with the requests spread over two API nodes). GET β¦/rows/a.
π Expected behavior
Exactly one commit succeeds, the other answers 400 transaction_not_ready. The row has n = 1.
π Actual Behavior
Both requests answer 200 with status: committed, and the operations run once per request:
| Parallel commits | Stored n (3 rounds each) |
|---|---|
| 2 | 2, 2, 2 |
| 4 | 4, 4, 4 |
| 8 | 7 (one request got transaction_not_ready), 8, 8 |
Two further runs of the 2-commit and 8-commit case gave 2 and 8 again. A second commit sent after the first one finished is rejected correctly.
With a create operation the first commit succeeds and the others answer 409 transaction_conflict; the transaction then ends up with status failed although the row was created (3 of 3 rounds with 4 parallel commits). For increment, decrement and operator updates there is no conflict, so the change is applied several times without any error.
Cause: Transactions\Update::action() reads the transaction and checks status === 'pending' (Update.php L139), and only later writes status = 'committing' with a plain updateDocument() (L197βL201). Nothing locks the transaction or compares the status atomically between the check and the write, so every request that read pending before the first write runs the whole operation list in its own database transaction. main has the same check and write (Update.php L143 and L204; read, not run).
π² Appwrite version
2.3.0
π» Operating system
Linux (Debian 12), Docker
π§± Your Environment
Self-hosted Appwrite 2.3.0, Postgres adapter, two API nodes behind a load balancer, Postgres on a separate node.
π‘ Suggested fix
Claim the transaction atomically before applying anything, for example UPDATE β¦ SET status = 'committing' WHERE status = 'pending' and continue only if one row changed, or SELECT β¦ FOR UPDATE on the transaction row inside a database transaction. Otherwise answer transaction_not_ready.
π Have you spent some time to check if this issue has been raised before?
- I checked and didn't find a similar issue
π’ Have you read the Code of Conduct?
- I have read the Code of Conduct
Activity