MagicStack / MagicStack/asyncpg

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

Open
#736 2 comments 3 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
8.1k
Forks
468
PR merge metrics
No merged PRs in 30d

Description

* **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](https://github.com/magicstack/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':,
'user': ,
'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)

```

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the supplied Sanic reproduction, focusing on asyncpg.create_pool, max_inactive_connection_lifetime, and the connection acquire/release path. Run it against AWS Aurora and compare its behavior with local PostgreSQL under uvloop. Done means the connection-reset behavior is explained and a verified fix or narrowly scoped next step is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.