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

Calling aiopg.createPool() a 2nd time if first failed results in: RuntimeError: unable to perform operation on <UVPoll closed=True 0x105fd4270>; the handler is closed #909

Open
1 task done
maxnet opened this issue Jul 21, 2024 · 0 comments
Labels

Comments

@maxnet
Copy link

maxnet commented Jul 21, 2024

Describe the bug

If aiopg.create_pool() fails because the PostgreSQL server is down it gives a psycopg2.OperationalError "Error connecting to database: Connection refused"
If you subsequently want to retry and call aiopg.create_pool() a second time it results in a "RuntimeError: unable to perform operation on <UVPoll closed=True 0x1046082e0>; the handler is closed" error.

To Reproduce

  1. make sure your database server is down, or just point DSN to an IP that has no database server for testing purposes
  2. use code among the lines of:
db_pool = False
dsn = "dbname=mydb user=myuser password=mypassword host=127.0.0.1"

async def init():
    global db_pool
    while True:
        try:
            db_pool = await aiopg.create_pool(dsn, maxsize=4, timeout=10, pool_recycle=300)
            break
        except psycopg2.OperationalError as ex:
            print("Error connecting to database: %s" % ex)
            print("Trying again in 5 seconds...")
            await asyncio.sleep(5)

Expected behavior

Expect it to retry connecting to the database server.

Logs/tracebacks

File "MYFILE.py", line 93, in init
    db_pool = await aiopg.create_pool(dsn, maxsize=4, timeout=10, pool_recycle=300)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/aiopg/pool.py", line 300, in from_pool_fill
    await self._fill_free_pool(False)
  File "/opt/homebrew/lib/python3.12/site-packages/aiopg/pool.py", line 336, in _fill_free_pool
    conn = await connect(
                 ^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/aiopg/connection.py", line 65, in connect
    connection = Connection(
                 ^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/aiopg/connection.py", line 772, in __init__
    self._loop.add_reader(
  File "uvloop/loop.pyx", line 2441, in uvloop.loop.Loop.add_reader
  File "uvloop/loop.pyx", line 780, 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 0x1046082e0>; the handler is closed

Python Version

Python 3.12.4

aiopg Version

Version: 1.4.0

OS

macOS

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@maxnet maxnet added the bug label Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant