aio-libs / aio-libs/aiopg

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

Abierto
#909 1 comentario 0 reacciones 0 asignados Ver en GitHub
bug
Lenguaje dominante
Python
Estrellas
1.4k
Forks
170
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

### 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 ; 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:

```python
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

```python-traceback
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 ; the handler is closed
```

### Python Version

```console
Python 3.12.4
```

### aiopg Version

```console
Version: 1.4.0
```

### OS

macOS

### Additional context

_No response_

### Code of Conduct

- [X] I agree to follow the aio-libs Code of Conduct

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.