aio-libs / aiopg

aiopg is a library for accessing a PostgreSQL database from the asyncio
http://aiopg.readthedocs.io
BSD 2-Clause "Simplified" License
1.4k stars 160 forks source link

unable to perform operation on <UVPoll closed=True 0x7fe55db27270>; the handler is closed #856

Open letrec opened 3 years ago

letrec commented 3 years ago

I have a server application where after some time being idle the below occurs:

unable to perform operation on <UVPoll closed=True 0x7fe55db27270>; the handler is closed
Traceback (most recent call last):
    async with pool.acquire() as conn:
  File "/home/test/venv/lib/python3.8/site-packages/aiopg/utils.py", line 69, in __aenter__
    self._obj = await self._coro
  File "/home/test/venv/lib/python3.8/site-packages/aiopg/pool.py", line 164, in _acquire
    await self._fill_free_pool(True)
  File "/home/test/venv/lib/python3.8/site-packages/aiopg/pool.py", line 211, in _fill_free_pool
    conn = await connect(
  File "/home/test/venv/lib/python3.8/site-packages/aiopg/connection.py", line 38, in connect
    coro = Connection(
  File "/home/test/venv/lib/python3.8/site-packages/aiopg/connection.py", line 90, in __init__
    self._loop.add_reader(self._fileno, self._ready, self._weakref)
  File "uvloop/loop.pyx", line 2419, in uvloop.loop.Loop.add_reader
  File "uvloop/loop.pyx", line 777, in uvloop.loop.Loop._add_reader
  File "uvloop/handles/poll.pyx", line 104, in uvloop.loop.UVPoll.start_reading
  File "uvloop/handles/poll.pyx", line 39, in uvloop.loop.UVPoll._poll_start
  File "uvloop/handles/handle.pyx", line 159, in uvloop.loop.UVHandle._ensure_alive
RuntimeError: unable to perform operation on <UVPoll closed=True 0x7fe55db27270>; the handler is closed

I suspect the connection gets stale, but the pooling logic doesn't check for that. It looks like the check at https://github.com/aio-libs/aiopg/blob/master/aiopg/pool.py#L324 needs to account for that similar to https://github.com/aio-libs/aiomysql/pull/339/files#diff-9ccf7da6bb12e81af8f2eefbd1c5b43ebc6695d4d750a29683e90024156bc03fR151