Pool.wait_closed call to Connection.close raising pyodbc.ProgrammingError
- Langage dominant
- Python
- Étoiles
- 326
- Forks
- 62
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
# Stack trace
```
[INFO 2025-01-22 10:49:11] Waiting for application shutdown.
[ERROR 2025-01-22 10:49:11] Traceback (most recent call last):
File "C:\Program Files\Python313\Lib\site-packages\starlette\routing.py", line 693, in lifespan
async with self.lifespan_context(app) as maybe_state:
~~~~~~~~~~~~~~~~~~~~~^^^^^
File "C:\Program Files\Python313\Lib\contextlib.py", line 221, in __aexit__
await anext(self.gen)
File "C:\Program Files\Python313\Lib\site-packages\litumtap\litumserver.py", line 47, in lifespan
async with dependencies.data_adapter as db:
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python313\Lib\site-packages\litumtap\data_adapter.py", line 58, in __aexit__
await pool.wait_closed()
File "C:\Program Files\Python313\Lib\site-packages\aioodbc\pool.py", line 111, in wait_closed
await conn.close()
File "C:\Program Files\Python313\Lib\site-packages\aioodbc\connection.py", line 137, in close
c = await self._execute(self._conn.close)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python313\Lib\concurrent\futures\thread.py", line 59, in run
result = self.fn(*self.args, **self.kwargs)
pyodbc.ProgrammingError: Attempt to use a closed connection.
[ERROR 2025-01-22 10:49:11] Application shutdown failed. Exiting.
[CRITICAL 2025-01-22 10:49:11] Service ended
```
Is there a reason the fix that went into Pool._fill_free_pool (catch ProgrammingError) wasn't applied in other places?
It is also looking like this catch should have been done in Connection.close instead.
It is also important to note that this issue is occuring elsewhere as well.
```
| ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "C:\Program Files\Python313\Lib\site-packages\litumtap\data_adapter.py", line 37, in get_person_by_entity
| return await self._query_one(
| ^^^^^^^^^^^^^^^^^^^^^^
| self._to_person, self.GET_PERSON_BY_ENTITY, entity_id
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| )
| ^
| File "C:\Program Files\Python313\Lib\site-packages\litumtap\data_adapter.py", line 77, in _query_one
| async with self._pool.acquire() as conn, conn.cursor() as cursor:
| ~~~~~~~~~~~^^
| File "C:\Program Files\Python313\Lib\site-packages\aioodbc\utils.py", line 86, in __aenter__
| self._obj = await self._coro
| ^^^^^^^^^^^^^^^^
| File "C:\Program Files\Python313\Lib\site-packages\aioodbc\connection.py", line 123, in _cursor
| c = await self._execute(self._conn.cursor)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "C:\Program Files\Python313\Lib\concurrent\futures\thread.py", line 59, in run
| result = self.fn(*self.args, **self.kwargs)
| pyodbc.ProgrammingError: Attempt to use a closed connection.
+------------------------------------
```
It seems Pool.aquire is returning closed connection and then Connection.cursor raises ProgrammingError when _execute is called.
I believe this is related as well:
```
| pyodbc.OperationalError: ('08S01', '[08S01] [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: An existing connection was forcibly closed by the remote host.\r\n (10054) (SQLExecDirectW); [08S01] [Microsoft][ODBC Driver 17 for SQL Server]Communication link failure (10054)')
```
Connection class seems unable to track connection state.
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.