Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pool.wait_closed call to Connection.close raising pyodbc.ProgrammingError #464

Open
skewty opened this issue Jan 22, 2025 · 0 comments
Open

Comments

@skewty
Copy link

skewty commented Jan 22, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant