aio-libs/aioodbc

Bad connections should not be put back into the pool

thehesiod opened this issue · 2 comments

Pool.acquire returns a _PoolConnectionContextManager.

After __aenter__ a pyodbc.OperationalError: ('08S01', '[08S01] [Microsoft][ODBC Driver 17 for SQL Server]Communication link failure (0) (SQLExecDirectW)') can be thrown in which case the connection may be permanently bad.

We now go to its __aexit__ where it unconditionally calls await self._pool.release(self._conn).

Pool.release at this point doesn't know if the connection is bad.

Instead if pyodbc.OperationalError is raised the connection should probably always be closed.

btw hello @jettify on another aio project :]

In my case . we used this "'exec sp_change_users_login 'AUTO_FIX',"cause DB was updated and for this user we made auto_fix