Skip to content

Doc: @Retryable around @Transactional might run a committed transaction again when the COMMIT reply is lost #37696

Done

Description

@KurathSec

Versions. Spring Framework 7.0.10 (spring-context, spring-jdbc), pgjdbc 42.7.14, Java 25.0.4.1; PostgreSQL 13.23 and 18.6.

What happens

A method annotated @Retryable, with its defaults, calls a @Transactional method that inserts one row. When the COMMIT's reply is lost after the server committed, the commit raises an exception, @Retryable retries, and a new transaction inserts the row again. Two rows are inserted and the caller sees a normal return.

Reproduction

@Retryable public void write(String token) calling @Transactional void insert(String token) on another bean (jdbcTemplate.update("INSERT INTO b_events (token) VALUES (?)", token)), with @EnableResilientMethods and @EnableTransactionManagement, through a TCP proxy between the client and PostgreSQL that forwards the COMMIT and then closes both sides of that one connection without forwarding the server's reply; later connections pass through untouched. The same for an autocommit insert, when the server terminates the session after committing, and when a termination ends a synchronous commit wait. A minimal reproducer of the first case is attached.

Expected

One row, or the failure reported to the caller.

Observed

Two rows and a normal return in every run (36 of n=36 over a lost reply, an injected termination and a synchronous-commit termination, each inside a transaction and in autocommit, on PostgreSQL 13.23 and 18.6). With a UNIQUE constraint on the token, the retry failed with 23505 and the caller received that error for a write that had committed (36 of n=36). Where the COMMIT never reached the server, the retry applied the row once. The archived spring-retry 2.0.13 gives the same two results (36 of n=36 without the constraint).

Why

@Retryable retries any exception by default, with three retries 1 s apart (Retryable.java:91, 128, 181 at v7.0.10). The Resilience section says of @Transactional that "the current transaction has already been rolled back by the time the retry interceptor receives the exception" (framework-docs/modules/ROOT/pages/core/resilience.adoc:152-154). That does not hold when the exception comes from a COMMIT whose reply was lost: the transaction may have committed.

A possible remedy

A note in that section that an exception raised by the commit itself can leave the outcome unknown, so a retry can apply the work twice unless the work is idempotent or the outcome is resolved first.

What this does not show

One driver; the defaults of @Retryable only, not a narrower includes such as the TransientDataAccessException of the documentation's example; how often a commit reply is lost in production.

spring-framework-retryable.zip

Activity

  1. added
    status: waiting-for-triage
    on Nov 16, 2026
  2. added
    in: core
    on Nov 17, 2026
  3. self-assigned this
    on Nov 19, 2026
  4. added
    type: documentation
    and removed
    status: waiting-for-triage
    in: core
    on Nov 19, 2026
  5. added this to the 7.1.1 milestone on Nov 19, 2026
  6. changed the title [-]`@Retryable` around `@Transactional` runs a committed transaction again when the COMMIT reply is lost[/-] [+]Doc: `@Retryable` around `@Transactional` might run a committed transaction again when the COMMIT reply is lost[/+] on Nov 19, 2026
  7. added a commit that references this issue on Nov 23, 2026
    e30919d
  8. added
    for: backport-to-7.0.x
    on Nov 24, 2026
  9. added
    status: backported
    and removed
    for: backport-to-7.0.x
    on Nov 24, 2026
  10. added a commit that references this issue on Nov 24, 2026
    20289df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

status: backportedtype: documentation

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions