UDPTransport.abort() with a queued datagram reports a fatal write error and a resume_writing() AttributeError
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 68/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- python
- Domínio
- networking
Direção de pesquisa
Start by reproducing the issue with the provided script, then trace UDPTransport.abort() and UVBaseTransport._maybe_resume_protocol to see how queued-send cancellation and protocol detachment interact. Compare the exception-handler output with vanilla asyncio; done means abort discards the queued datagram without reporting either error, while connection_lost(None) still occurs.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
- uvloop version: 0.23.0 (also 0.22.1)
- Python version: 3.12.3
- Platform: Linux (x86_64, glibc 2.39)
- Can you reproduce the bug with
PYTHONASYNCIODEBUGin env?: Yes - Does uvloop behave differently from vanilla asyncio? How?: Yes. With vanilla asyncio,
abort()silently discards the queued datagram and callsconnection_lost(None). With uvloop,connection_lost(None)is called too, but two errors are also passed to the loop's exception handler.
Calling abort() on a UDPTransport while a datagram is still queued (because the OS refused it with EAGAIN) reports two errors to the loop's exception handler:
Fatal error on transport UDPTransport (Fatal write error on datagram transport), withexception=CancelledError(). The queued send is cancelled because we aborted, so this is not an error.protocol.resume_writing() failed, withAttributeError("'NoneType' object has no attribute 'resume_writing'"), raised fromUVBaseTransport._maybe_resume_protocolafter the protocol has already been detached.
A UNIX datagram socket is used to make the OS refuse datagrams, because UDP on loopback never exerts back-pressure. The peer never reads, so the send buffer fills up.
import asyncio
import socket
import sys
import tempfile
import uvloop
class Protocol(asyncio.DatagramProtocol):
def connection_made(self, transport):
transport.set_write_buffer_limits(0)
def connection_lost(self, exc):
print("connection_lost", exc)
async def main():
loop = asyncio.get_running_loop()
errors = []
loop.set_exception_handler(lambda loop, context: errors.append(context))
path = f"{tempfile.mkdtemp()}/peer.sock"
peer = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
peer.bind(path) # never read from
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
sock.connect(path)
sock.setblocking(False)
transport, _ = await loop.create_datagram_endpoint(Protocol, sock=sock)
# Send until the OS refuses a datagram and the transport has to queue it
while not transport.get_write_buffer_size():
transport.sendto(b"x" * 64)
transport.abort()
await asyncio.sleep(0.1)
for context in errors:
print("exception handler:", context["message"], repr(context.get("exception")))
if sys.argv[1:] == ["uvloop"]:
uvloop.run(main())
else:
asyncio.run(main())
Output with python repro.py:
connection_lost None
Output with python repro.py uvloop:
connection_lost None
exception handler: Fatal error on transport UDPTransport (Fatal write error on datagram transport) CancelledError()
exception handler: protocol.resume_writing() failed AttributeError("'NoneType' object has no attribute 'resume_writing'")
Expected: the same as vanilla asyncio, i.e. the queued datagram is silently discarded and nothing is reported to the exception handler.
Found via anyio, whose UDP socket aclose() aborts the transport.
- Linguagem predominante
- Cython
- Estrelas
- 11.9k
- Forks
- 616
- Merge médio
- 4h 43min
- PRs com merge (30d)
- 3
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de MagicStack/uvloop
-
uv 1.53.0 fixTalvez já em andamento @fantix assumiu hoje. Aberta
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 85/100
MagicStack/uvloop#774 · 1 comentário · 1 reação ·
-
License not clearAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
MagicStack/uvloop#759 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
MagicStack/uvloop#741 · 2 reações ·
-
`asyncio.get_event_loop` raises error instead of spawning new loop when no loop is running.Talvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
MagicStack/uvloop#702 · 8 comentários · 9 reações ·
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 25/100
MagicStack/uvloop#773 ·
Todas as issues de MagicStack/uvloop
Issues semelhantes
-
area/security
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
agent-substrate/substrate#2276 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
v2fly/domain-list-community#4127 ·
Mantenedores costumam responder em até 2 dias
-
enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
QuantumSavory/QuantumSavory.jl#592 ·
Mantenedores costumam responder em até 1 dia
-
DataQuery closes the response body without draining it, so HTTP connections to Loki are never reusedAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
grafana/grafana-loki-datasource#205 ·
Mantenedores costumam responder em até 1 dia