Make the database backend retry operations on ResourceClosedError and StaleDataError too. Make the operations close the connection if failure occurs (can't retry on broken connection). Fixes #1786.