DB connection exception on rollback causes connection leak

Description

SessionImpl.close() doesn't close db connections after an exception occurs in java.sql.Connection.rollback(). The db connection remains active in the connection pool and is never released. An exception can occur in Connection.rollback(), for example, when the db connection is lost.

Example included, the example uses a subclassed h2 database connection and simulates an exception when calling transaction.rollback().

I understand normally db connection errors are a larger problem that should be addressed outside of hibernate, but in the pathological case where db connections drop it could cause a knock on effect to use up all connections in the db pool. Note that a connection error when issuing a normal query will get converted into a rollback.

Environment

None

Assignee

Andrea Boriero

Reporter

Mark Watson

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure