Database connection pool: more robust code in case the connection becomes stale.
In particular, this takes into account the fact that a `rollback` can fail at a critical time, as shown in #3894. Also, when a connection is closed in such cases, the `_cursize` must be decremented.