MagicStack / asyncpg

A fast PostgreSQL Database Client Library for Python/asyncio.
Apache License 2.0
6.88k stars 399 forks source link

Fetch from PostgreSQL 10 hangs forever #994

Closed grinspins closed 1 year ago

grinspins commented 1 year ago

According to the README Postgres 9.5 and up are supported, but I'm unable to fetch data from a Postgres 10.6 DB. The following code just hangs forever against 10.6. The only other Postgres version I could test was 15 and the code runs without issues.

import asyncio
import asyncpg

async def run():
    conn = await asyncpg.connect(user='user', password='password',
                                 database='my db', host='localhost')
    values = await conn.fetch(
        'SELECT * FROM my.table limit 5'
    )
    await conn.close()

asyncio.run(run())

Killing it with ctrl+c consistently gives the following stacktrace:

File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 650, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/test.py", line 7, in run
    values = await conn.fetch(
             ^^^^^^^^^^^^^^^^^
  File "/python3.11/site-packages/asyncpg/connection.py", line 620, in fetch
    return await self._execute(
           ^^^^^^^^^^^^^^^^^^^^
  File "/python3.11/site-packages/asyncpg/connection.py", line 1658, in _execute
    result, _ = await self.__execute(
                ^^^^^^^^^^^^^^^^^^^^^
  File "/python3.11/site-packages/asyncpg/connection.py", line 1683, in __execute
    return await self._do_execute(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/python3.11/site-packages/asyncpg/connection.py", line 1710, in _do_execute
    stmt = await self._get_statement(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python3.11/site-packages/asyncpg/connection.py", line 397, in _get_statement
    statement = await self._protocol.prepare(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "asyncpg/protocol/protocol.pyx", line 168, in prepare
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/test.py", line 13, in <module>
    asyncio.run(run())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 123, in run
    raise KeyboardInterrupt()
KeyboardInterrupt

If it's not a general issue with Postgres 10 are there any DB settings known to interfere with asyncpg that I could check?

grinspins commented 1 year ago

Never mind. Looks like the postgres version wasn't at fault, but the faulty DB is deployed behind pgpool-II. https://github.com/MagicStack/asyncpg/issues/573

grinspins commented 1 year ago

Upgrade to pgpool-II 4.4.0 resolved the issue.