Fix race condition in DB shutdown
- Fix a potential race condition where startTransaction() is called concurrently with closeAllConnections(), such that closeAllConnections() sets
closed = true
after startTransaction() has checked that it's false - When a transaction is aborted, close the connection instead of returning it to the pool
- When a transaction fails to commit, close the connection instead of returning it to the pool