You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But I think this is wrong way: you shouldn't create_engine on every DB call. So engine object should be reusable instance in whole app. I've tried to use it like this:
# Somewhere on app init stage:asyncdefinit_db_engine():
db_engine=awaitaiopg.sa.create_engine(**engine_init_params)
returndb_engine# Somewhere on app stop stage:asyncdefrelease_db_engine(db_engine):
db_engine.close()
returnawaitdb_engine.wait_closed()
# In some handlers:asyncdefget(*args, **kwargs):
redirect_table=app.db.models.redirect.Redirect.__table__asyncwithself.application.db.acquire() asconn:
redirect_query=redirect_table.select().where(...)
redirect_query_result=awaitconn.execute(redirect_query)
redirect_info=awaitredirect_query_result.fetchone()
All looks like good, but... After some time of program inactivity any call to database fails with error:
value = future.result()
resp = yield from self._coro
redirect_query_result = await conn.execute(redirect_query)
File "/usr/local/lib/python3.6/site-packages/aiopg/utils.py", line 72, in __await__
File "/usr/local/lib/python3.6/site-packages/aiopg/cursor.py", line 113, in execute
File "/usr/local/lib/python3.6/site-packages/aiopg/connection.py", line 237, in _poll
yield from self._conn._poll(waiter, timeout)
yield from cursor.execute(str(compiled), post_processed_params[0])
File "/usr/local/lib/python3.6/site-packages/aiopg/sa/connection.py", line 110, in _execute
return fut.result()
File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
File "/usr/local/lib/python3.6/site-packages/aiopg/connection.py", line 134, in _ready
yield from asyncio.wait_for(self._waiter, timeout, loop=self._loop)
psycopg2.OperationalError: server closed the connection unexpectedly before or while processing the request. This probably means the server terminated abnormally
Next call - works fine, so connection is reistablished.
What I've tried:
Add parameter pool_recycle=1 to engine_init_params - it is not recognized
Add minsize and maxsize parameters to engine_init_params - this didn't help
The text was updated successfully, but these errors were encountered:
I can't reproduce this issue on localhost (and/or) in debugger. But on real production environment in Docker, when DB and application running in different containers over network - it reproduces with 100% chance.
I'm using aiopg with SqlAlchemy support. All your examples looks like:
But I think this is wrong way: you shouldn't
create_engine
on every DB call. So engine object should be reusable instance in whole app. I've tried to use it like this:All looks like good, but... After some time of program inactivity any call to database fails with error:
Next call - works fine, so connection is reistablished.
What I've tried:
pool_recycle=1
toengine_init_params
- it is not recognizedminsize
andmaxsize
parameters toengine_init_params
- this didn't helpThe text was updated successfully, but these errors were encountered: