TLS/SSL asyncio/uvloop leaks memory
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- python
- Domain
- networking
Research direction
Start with the minimal asyncio.Protocol reproducer using uvloop.new_event_loop, loop.create_server, and the TLS context, then run the provided ab -n15000 -c15000 -r command on Linux across the reported Python versions. Compare memory behavior with and without TLS and uvloop; done means the leak is isolated and memory no longer grows excessively under the reproduced load.
Written by the indexing model from the issue text.
Description
python3.9 or uvloop seems to leak smaller, but python3.11 (and others?) leaks A LOT OF memory under load
test command: ab -n15000 -c15000 -r https://127.0.0.1/
(apt install apache2-utils)
import asyncio, ssl, uvloop
class HTTP(asyncio.Protocol):
def __init__(self):
self.transport = None
def connection_made(self, transport) -> None:
self.transport = transport
def data_received(self, data) -> None:
self.transport.write(
b'HTTP/1.1 200 OK\r\nContent-Length: 0\r\nConnection: keep-alive\r\n\r\n'
)
self.transport.close()
def connection_lost(self, _=0) -> bool | None:
self.transport.close()
def make_tls_context():
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ctx.load_cert_chain('cert.crt', 'cert.key')
return ctx
tls_context = make_tls_context()
loop = uvloop.new_event_loop()
loop.set_debug(True)
async def start_server(loop):
return await loop.create_server(
HTTP, '127.0.0.1', 443, backlog=65535,
ssl=tls_context)
loop.run_until_complete(start_server(loop))
loop.run_forever()
loop.close()
CPython versions tested on:
3.9, 3.11
Operating systems tested on:
Linux
- Dominant language
- Cython
- Stars
- 11.9k
- Forks
- 615
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from MagicStack/uvloop
-
License not clear Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MagicStack/uvloop#759 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MagicStack/uvloop#741 · 2 reactions ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MagicStack/uvloop#702 · 8 comments · 9 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
MagicStack/uvloop#766 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
MagicStack/uvloop#765 ·
All issues in MagicStack/uvloop
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
sonic-net/sonic-mgmt#28113 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
canonical/postgresql-watcher-operator#110 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
EleutherAI/lm-evaluation-harness#4201 ·