When running tests on PostgreSQL with a max_connections value of 10, the tests are failing because connections are still in use. We need to add proper resource handling so that even if we get an exception, the transaction is rolled back and the connections are released.
Fixed all connections leaks and tested it on H2 and PostgreSQL. For PostgreSQL, it worked even with just 10 max_connections.
Fixed in 5.1 branch as well.