Skip to content

πŸ› Bug Report: Concurrent commits apply a transaction more than onceΒ #14142

Closed

Description

@JoshiJoshiJoshi

πŸ‘Ÿ Reproduction steps

  1. Table with an integer column n; row a with n = 0.
  2. POST /v1/tablesdb/transactions with {"ttl": 300} β†’ transaction {transactionId}.
  3. POST /v1/tablesdb/transactions/{transactionId}/operations with one operation: {"action": "increment", "databaseId": "{databaseId}", "tableId": "{tableId}", "rowId": "a", "data": {"column": "n", "value": 1}}.
  4. 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).
  5. 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

  1. added
    product / databases
    sdk / cli
    on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    product / databasessdk / cli

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions