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

Fix pyodbc.ProgrammingError: Attempt to use a closed connection. #382

Merged
merged 1 commit into from Mar 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion aioodbc/pool.py
Expand Up @@ -4,7 +4,10 @@
import asyncio
import collections

from pyodbc import ProgrammingError

from .connection import connect
from .log import logger
from .utils import _PoolContextManager, _PoolConnectionContextManager

__all__ = ['create_pool', 'Pool']
Expand Down Expand Up @@ -137,7 +140,16 @@ async def _fill_free_pool(self, override_min):
conn = self._free[-1]
if self._recycle > -1 \
and self._loop.time() - conn.last_usage > self._recycle:
await conn.close()

try:
if not conn.closed:
await conn.close()
except ProgrammingError as e:
# Sometimes conn.closed is False even if connection has been already closed
# (ex. for impala driver clouderaimpalaodbc_2.6.16.1022-2_amd64.deb).
# conn.close() will raise ProgrammingError in this case.
logger.warning(e)

self._free.pop()
else:
self._free.rotate()
Expand Down