Continuous memory increase in Sanic web server after calling `loop.start_tls(...)` in `connect_utils._create_ssl_connection`
Maintainer antworten meist innerhalb von 1 Tag
@fantix arbeitet bereits daran.
Seit 17.2.2023.
Bewertung
Dieses Issue wurde noch nicht bewertet.
Beschreibung
- asyncpg version:
0.2.7 - PostgreSQL version:
PostgreSQL 13.3 (Debian 13.3-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit - Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?: I use PostgreSQL installed in docker imagekartoza/postgis:pr-333-13-3.1 - Python version:
3.8.10 - Platform:
20.04.1-Ubuntu x86_64 - Do you use pgbouncer?: Not sure, I use it indirectly. (behind
sqlalchemy) - Did you install asyncpg with pip?: Yes
- If you built asyncpg locally, which version of Cython did you use?: /
- Can the issue be reproduced under both asyncio and
uvloop?: I see the code below is based on uvloop.
Background: I built a simple web server using sqlalchemy and sanic, then created a request handler function that can query my local PostgreSQL server running in docker. However, I saw continuous memory increase while benching my handler function.
After running tracemalloc for help, I got the result below:
Top 10 lines
#1: /home/tusimple/Workspace/projects/map-workdata-manager/venv/lib/python3.8/site-packages/asyncpg/connect_utils.py:700: 5670.1 KiB
new_tr = await loop.start_tls(
The code for creating the async_engine is:
from sqlalchemy.ext.asyncio import create_async_engine
engine = create_async_engine("postgresql+asyncpg://{}:{}@{}/{}".format(...))
At first, I tried adding ?ssl=disable after the previous connect string in order to prevent connect_utils._create_ssl_connection calls, and it works.
Then, I tried to make some stupid changes to the source code of asyncpg, because I think this SSL transport is not closed after creating new transport. (I'm not sure is that correct)
# line 697
if hasattr(loop, 'start_tls'):
if do_ssl_upgrade:
try:
new_tr = await loop.start_tls(
tr, pr, ssl_context, server_hostname=host) # <--- here
except (Exception, asyncio.CancelledError):
tr.close()
raise
else:
new_tr = tr
# line 706
Finally, I modified the code starts from line 702 to:
except (Exception, asyncio.CancelledError):
raise
finally:
tr.close()
After this modification, my web server keeps working fine, but I don't know whether this is a proper modification.
If you have any questions or ideas, please let me know, thank you so much!
- Vorherrschende Sprache
- Python
- Sterne
- 8.1k
- Forks
- 474
- Ø Merge
- 1 T. 17 Std.
- Gemergte PRs (30 T.)
- 24
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus MagicStack/asyncpg
-
Failed BEGIN leaves Connection._top_xact set; every later transaction becomes a SAVEPOINT and fails with NoActiveSQLTransactionErrorEvtl. vergeben @devtechedge hat das vor 5 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 35/100
MagicStack/asyncpg#1386 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Connect call failed error doesn't distinguish port mismatch from "server not running"Evtl. vergeben @aryansk hat das vor 58 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
MagicStack/asyncpg#1342 ·
Maintainer antworten meist innerhalb von 1 Tag
-
TypeError in asyncpg.connect() for specific parameters when values are not str enoughEvtl. vergeben @pranjalm37 hat das vor 61 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 56/100
MagicStack/asyncpg#1340 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
setup.py relies on deprecated pkg_resourcesEvtl. vergeben @jasonwbarnett hat das vor 89 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 28/100
MagicStack/asyncpg#1337 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 42/100
MagicStack/asyncpg#1330 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in MagicStack/asyncpg
Ähnliche Issues
-
area: agents area: docs good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
openapi/gknowledge#23 ·
-
get() for StrEnumEvtl. vergeben @FeJo5952 hat das heute übernommen. Offengood first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
collective/icalendar#1921 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Improvement Python Spans
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
getsentry/sentry-python#7994 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
alphagov/notifications-api#5004 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
equinor/radix-flux#3922 ·
Maintainer antworten meist innerhalb von 1 Tag