Skip to content

RemoteDatabase.transaction() retries a joined transaction and never rolls back a failed attempt - two guards LocalDatabase has (one citing #661) #7030

Closed

Description

@ruispereira

Summary

RemoteDatabase.transaction() is missing two guards that LocalDatabase.transaction() has, one of which carries an in-code comment naming the issue (#661) that established it. The result: a retry can fire on a transaction the caller owns, and a failed attempt never rolls back the server-side transaction before the next attempt races it.

Where (HEAD c50338bd8)

LocalDatabase.java, the retry catch arm - the guard and the rollback:

} catch (final NeedRetryException | DuplicatedKeyException e) {
  // #661: when we joined a transaction owned by the caller (createdNewTx == false) we must NOT retry
  ...
  if (!createdNewTx)
    throw e;
  ...
  if (wrappedDatabaseInstance.isTransactionActive())
    wrappedDatabaseInstance.rollback();

and its catch (final Throwable e) arm also rolls back before rethrowing.

network/src/main/java/com/arcadedb/remote/RemoteDatabase.java:244-266 has neither. Both catch arms - catch (NeedRetryException | DuplicatedKeyException) and catch (Exception) - go straight to the error callback and the loop, with no !createdNewTx test and no rollback() anywhere in the method's failure paths.

The two implementations are otherwise structurally identical: the same for (int retry = 0; retry < attempts; ++retry), the same if (joinCurrentTransaction && isTransactionActive()) createdNewTx = false; else begin();. So this is a parity gap, not a design difference.

Impact, part 1 - retrying a transaction the caller owns

transaction(block, true) that joins an outer transaction and then hits a NeedRetryException re-runs block inside the caller's still-open transaction. The caller's transaction accumulates the partial effects of the failed attempt plus the retry, and the caller is never told. That is exactly what #661 fixed locally.

Impact, part 2 - no rollback before the retry

Each failed attempt leaves the server-side transaction open, holding its locks. The loop then immediately begins a new one, so attempt N+1 contends with the locks of attempt N, which makes a NeedRetryException more likely rather than less - the retry can make the situation worse. On the final failure the server-side transaction is left open until its own timeout.

Suggested fix

Port both guards:

} catch (final NeedRetryException | DuplicatedKeyException e) {
  if (!createdNewTx)
    throw e;
  if (isTransactionActive())
    rollback();
  ...

and add the rollback() to the general catch arm too. rollback() already exists on this class (:391) and sends POST /rollback.

Worth extracting the shared retry policy so the two implementations cannot drift again - that drift is what this issue is.

Scope / confidence

High. Both methods read end to end and compared; the #661 comment in the local one is direct evidence the guard is required rather than incidental.

Activity

  1. added
    network
    concurrency
    on Sep 2, 2026
  2. added this to the 26.9.1 milestone on Sep 2, 2026
  3. added
    in progress
    on Sep 3, 2026
  4. self-assigned this
    on Sep 3, 2026
  5. added a commit that references this issue on Sep 3, 2026
  6. lvca commented on Sep 3, 2026

    @lvca
    Member

    Fixed in #7085, milestone 26.9.1.

    RemoteDatabase.transaction() now behaves like the embedded one on failure:

    • It no longer retries a transaction you own. If you call transaction(block, true) from inside a transaction you opened yourself and the block hits a concurrency conflict, the block used to be re-run inside your still-open transaction, quietly leaving the partial effects of the failed attempt behind. Now the exception reaches you and you decide how to retry the whole unit of work.
    • Every failed attempt is rolled back before the next one. Previously the failed attempt's server-side transaction was left open holding its locks until the server timed it out, so the retry competed with the attempt that had just failed and was more likely to fail again, not less.

    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  7. removed
    in progress
    on Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugconcurrencynetwork

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions