Database.withTransaction hides the error that broke the transaction · Issue #14260 · playframework/playframework · GitHub
Skip to content

Database.withTransaction hides the error that broke the transaction #14260

Open

Description

@bursauxa

play.api.db.Database.withTransaction has a problem when a JDBC connection dies mid-transaction: it reports java.sql.SQLException: Connection is closed, and not the error that actually killed it.
The real cause never reaches the caller, and it never reaches the application logs either.
Both overloads are affected: the one taking an isolation level, and the one without.

The transaction itself is handled correctly, and every reproduction test checks that nothing was committed: the server rolls it back as soon as the connection goes away, whichever end of the socket failed.
What is lost is only the diagnosis, and it disappears precisely when a database starts misbehaving, in other words, at the very moment where a clear error message would be most valuable.

Reproduced with Play 3.0.11, MariaDB 11.4 and the MariaDB Connector/J 3.5.10.

Side note on H2 limitations

The project is tested exclusively against in-memory H2, which has no socket to time out, and no server to drop a session.
Neither the rollback() that withTransaction performs on the way out, nor the setTransactionIsolation() of its finally block, can ever throw there.

A fix can be tested against the following reproduction repo: https://github.com/bursauxa/play-sql-timeout-repro
But it bootstraps a TestContainers instance, so I am not sure it is worth it to keep in the in-project test suite.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions