python / python/cpython

asyncio.start_unix_server maybe shouldn’t default to cleanup_socket=True when sock parameter is passed

Aberta
#133,354 26 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

stdlib topic-asyncio type-bug
Linguagem predominante
Python
Estrelas
77.2k
Forks
36k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

Bug report

Bug description:

When asyncio.start_unix_server is called and the sock parameter is passed (rather than path), a server is wrapped around an existing socket. In this case, the fact that cleanup_socket defaults to True is very weird and potentially broken: it means that asyncio will try to delete a socket that someone else created (either other code in the same process, or, in the case of e.g. systemd socket passing, a socket created by a different program).

This is problematic for a couple of reasons when using systemd socket passing:

  • If the server succeeds at deleting the socket, it breaks socket activation. Socket activation means systemd creates the socket, and when the first connection arrives, it starts the server. The way it’s intended to work is that, if the server terminates, it leaves the socket in place, and systemd will start the server again if another connection comes in, allowing virtually seamless service restarts. If the server deletes the listening socket, this breaks.
  • If systemd passes the listening socket to the server, the server may not even have filesystem permission to see the socket—after all, only clients should need that. Then the os.stat call in create_unix_server blows up.

So this is definitely a nontrivial backwards compatibility break from 3.12 (which didn’t have cleanup logic at all and didn’t have the parameter) to 3.13, despite not being mentioned in the release notes. It also seems like a bit of a footgun in general, not to mention the fact that in implementation start_unix_server takes arbitrary kwargs and forwards them to create_unix_server, but the documentation instead mentions each parameter explicitly and doesn’t mention cleanup_socket at all.

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece com asyncio.start_unix_server e create_unix_server, concentrando-se no comportamento quando sock é fornecido e em como cleanup_socket é tratado. Revise a documentação de streams do asyncio vinculada na issue e a discussão existente nos comentários. O trabalho estará concluído quando o comportamento de sockets existentes e do repasse de sockets pelo systemd estiver resolvido, e a documentação ausente de cleanup_socket for abordada.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
backend-api-design, networking
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Precisa de esclarecimento
Facilidade para iniciantes
35/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.