MagicStack / MagicStack/asyncpg

asyncpg __del__ methods call asyncio APIs directly, which isn't guaranteed to work and indeed, doesn't work

Aberta
#376 1 comentário 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Linguagem predominante
Python
Estrelas
8.1k
Forks
468
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

asyncpg has several __del__ methods that call into asyncio APIs. But... you can't safely call into asyncio APIs from a __del__ method, because __del__ methods can be run in arbitrary threads, or at arbitrary moments when the loop's internal data structures are in an inconsistent state.

Discovered here: https://github.com/python-trio/trio-asyncio/issues/44

Looking at the traceback in that issue, I suspect that the reason this hasn't been noticed before is that the __del__ method ultimately ends up calling loop.call_soon(...). And if you do that from another thread, then with regular asyncio, things will mostly seem to work – it won't actually wake up the loop the way call_soon_threadsafe would, but if the loop is still running then it will eventually get run, and the default call_soon will not explode or otherwise notice if it's called from the wrong thread. But in that issue, someone's using asyncpg with an alternative asyncio loop that fails when call_soon is called from the wrong thread, and this breaks asyncpg.

I guess asyncpg should go through all its __del__ methods and wrap them in a loop.call_soon_threadsafe?

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

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 inventariando os métodos del do asyncpg e os caminhos de loop.call_soon implicados pela issue vinculada do Trio. Verifique cada caminho de limpeza em relação às preocupações de thread safety e de estado do loop descritas ali. Considera-se concluído quando o comportamento de limpeza afetado funcionar com implementações alternativas de loop do asyncio sem chamadas diretas inseguras.

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

Avaliação

Stack de tecnologia
postgresql, python
Domínio
databases
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
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.