Skip to content

agent: retry deadlocked PostgreSQL transactions, fail batches rolled back after an error - #2082

Draft
evgeny-simplex wants to merge 11 commits into
simplex-chat:stablefrom
evgeny-simplex:ep/agent-pg-batch-abort
Draft

evgeny-simplex wants to merge 11 commits into
simplex-chat:stablefrom
evgeny-simplex:ep/agent-pg-batch-abort

Conversation

@evgeny-simplex

Copy link
Copy Markdown
Contributor

On PostgreSQL, an agent transaction aborted by a deadlock was reported as INTERNAL instead of retried: in simplex-chat CI, the deletion of a delivered message and the deletion of its user deadlocked, and "delete user" failed (https://github.com/simplex-chat/simplex-chat/actions/runs/44067923868). And after a database error caught inside a transaction, PostgreSQL rolled the whole transaction back at COMMIT, while the batch items before the error were returned as saved.

Changes

  • agent: withStore, unsafeWithStore and withStoreBatch retry a transaction aborted by a deadlock or a serialization conflict (40P01, 40001) up to 3 times, as withTransactionIsolation already did for repeatable read. The handlers inside transactions (batch items, message storage, expired message deletion, record creation) let these conflicts reach the retry. SQLite is unchanged.
  • agent: on PostgreSQL, a database error in one item of a batch (withStoreBatch, message storage in enqueueMessageB) returns every item as failed, "transaction rolled back after ...", as the transaction is rolled back; rolled-back messages are not submitted for delivery.
  • agent: on PostgreSQL, a command for a deleted connection is not inserted, so the transaction that creates it is kept.
  • agent: deleted receive queues are counted after their batch, so a retried batch counts them once.
  • A retried transaction repeats the ERR events "no snd ratchet" and "no rcv ratchet". Expired message deletion no longer catches asynchronous exceptions, on SQLite too.

Tests

/Core tests/Agent core tests/

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant