MagicStack / MagicStack/uvloop
Server.serve_forever() isn't cancelled when Server.close() is called
Nessuno ha ancora preso questa issue.
- Lingua principale
- Cython
- Stelle
- 11.9k
- Fork
- 616
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
- uvloop version: 0.19.0
- Python version: 3.10.12 (3.10.12-1~22.04.3)
- Platform: Ubuntu 22.04.4
- Can you reproduce the bug with
PYTHONASYNCIODEBUGin env?: Yes - Does uvloop behave differently from vanilla asyncio? How?: Yes, described below.
With stock asyncio, after awaiting on Server.serve_forever(), calling Server.close() causes the await statement to throw CancelledError. With uvloop's implementation, the listening socket is correctly closed, however the await statement blocks indefinitely.
Example:
async def run_server():
async with await asyncio.start_server(lambda r,w: w.close(), '127.0.0.1', 8080) as server:
server.get_loop().add_signal_handler(15, lambda: server.close())
try:
await server.serve_forever()
except asyncio.CancelledError:
print('Shutting down')
uvloop.run(run_server())
The uvloop version closes the listening socket in response to SIGTERM, but never exits. The stock version prints Shutting down and exits.
Here's the CPython source where this is implemented:
https://github.com/python/cpython/blob/v3.8.18/Lib/asyncio/base_events.py#L341-L344
Thanks for taking a look!
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia confrontando il comportamento del server di uvloop con l’implementazione di CPython collegata in Lib/asyncio/base_events.py intorno alle righe 341–344, concentrandoti su Server.serve_forever() e Server.close(). Riproduci il problema con l’esempio SIGTERM fornito e conferma che la chiusura del server fa sì che serve_forever() sollevi asyncio.CancelledError e stampi “Shutting down” prima di terminare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend, networking
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100