asyncpg icon indicating copy to clipboard operation
asyncpg copied to clipboard

LOG: could not receive data from client: Connection reset by peer

Open anandhs opened this issue 4 years ago • 2 comments

  • asyncpg version: 0.22.0
  • PostgreSQL version: 12
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce the issue with a local PostgreSQL install?: AWS Aurora . Cannot reproduce with a local PostgreSQL.
  • Python version: v3.7.6+
  • Platform:
  • Do you use pgbouncer?: No
  • Did you install asyncpg with pip?: Yes
  • If you built asyncpg locally, which version of Cython did you use?: N/A
  • Can the issue be reproduced under both asyncio and uvloop?: just uvloop

It seems like asyncpg's connection pooler is not gracefully terminating connections. This seems to happen only with AWS Aurora version, but not the locally installed Postgres version.

Aurora Postgre has idle_in_transaction_session_timeout set to 86400000.

Here is the code to help reproduce this issue. .

from sanic import Sanic, Blueprint
from sanic.exceptions import NotFound
from sanic.response import json
from sanic.handlers import ErrorHandler
import asyncpg

app = Sanic(name="asyncpg-errors")
bp = Blueprint("info", url_prefix="/info")


DB_CONFIG = {
    'host':<url>,
    'user': <user>,
    'password': <password>,
    'port': 5432,
    'database': 'postgres'
}

def log_listener(connection, message):
    print(message)

@app.listener('before_server_start')
async def init(app, loop):
    app.pool = await asyncpg.create_pool(
        **DB_CONFIG, loop=loop,
        max_size=10, max_inactive_connection_lifetime=1
    )

@bp.route('/', methods=['GET'])
async def info(request):
    async with request.app.pool.acquire() as conn:
        conn.add_log_listener(log_listener)
        d = await conn.fetchrow('''SELECT * FROM mmrtest limit 1''')
        return json(dict(d))




group = Blueprint.group(bp)
app.blueprint(group)

app.run(port=9091, access_log=True, debug=True)

anandhs avatar Apr 04 '21 22:04 anandhs

Any updates on this issue? I'm experiencing something similar.

sada1993 avatar Aug 31 '21 22:08 sada1993

Also experiencing this issue, some insights would be helpful. Did anyone try disabling (i.e. setting to 0) idle_in_transaction_session_timeout and seeing if that helps?

andraspatka-dev avatar Nov 13 '23 16:11 andraspatka-dev