Ensure db connections are released when a thread exists.