Open bitrut opened 7 years ago
can you show code example? Make sure you do not reuse connection between coroutines
Does this usage could have an impact in this issue?
async def get_results():
async with engine.acquire() as conn:
return list(await conn.execute(sql))
for result in get_results():
...
Instead using async for
as docs suggests?
async with engine.acquire() as conn:
results = await conn.execute(sql)
async for result in results:
...
@bitrut both your examples are correct on first glance
I also can reproduce this error, would be up for working on a solution with the developers:
async def test_async():
pool = await aiopg.create_pool(DSN)
asyncio.run(test_async())
Traceback (most recent call last):
File "dbtest.py", line 25, in <module>
asyncio.run(test_async())
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 573, in run_until_complete
return future.result()
File "dbtest.py", line 19, in test_async
pool = await aiopg.create_pool(DSN)
File "/Users/cloudfind/Projects/mufasa/venv/lib/python3.7/site-packages/aiopg/utils.py", line 71, in __await__
resp = yield from self._coro
File "/Users/cloudfind/Projects/mufasa/venv/lib/python3.7/site-packages/aiopg/pool.py", line 47, in _create_pool
yield from pool._fill_free_pool(False)
File "/Users/cloudfind/Projects/mufasa/venv/lib/python3.7/site-packages/aiopg/pool.py", line 208, in _fill_free_pool
**self._conn_kwargs)
File "/Users/cloudfind/Projects/mufasa/venv/lib/python3.7/site-packages/aiopg/utils.py", line 66, in __iter__
resp = yield from self._coro
File "/Users/cloudfind/Projects/mufasa/venv/lib/python3.7/site-packages/aiopg/connection.py", line 74, in _connect
yield from conn._poll(waiter, timeout)
File "/Users/cloudfind/Projects/mufasa/venv/lib/python3.7/site-packages/aiopg/connection.py", line 240, in _poll
yield from asyncio.shield(cancel(), loop=self._loop)
File "/Users/cloudfind/Projects/mufasa/venv/lib/python3.7/site-packages/aiopg/connection.py", line 226, in cancel
self._conn.cancel()
psycopg2.OperationalError: asynchronous connection attempt underway
I have the same problem with using a single connection instead of a pool.
Connecting with the same DSN via psycopg2 or Postico works fine.
I went through official guide from Google on how to connect to Cloud PostgreSQL. Unfortunately I get this traceback in logs:
However, when I run application locally and connect via proxy running under docker with my laptop as I host it works fine. Anyone had problems with Google Cloud like mine?