-
-
Notifications
You must be signed in to change notification settings - Fork 162
Open
Labels
Description
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
- make sure your database server is down, or just point DSN to an IP that has no database server for testing purposes
- 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 closedPython Version
Python 3.12.4aiopg Version
Version: 1.4.0OS
macOS
Additional context
No response
Code of Conduct
- I agree to follow the aio-libs Code of Conduct