Skip to content

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

@anandhs

Description

@anandhs
  • 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions