asyncio: SSL transport raises AttributeError after close() in connection_lost()
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 25/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- À l'abandon
- Stack technique
- python
- Domaine
- networking
Piste de recherche
Start by locating _SSLProtocolTransport.close() and the asyncio SSL transport tests; the issue identifies that method as the source and includes a reproduction. Check the behavior of write(), set_protocol(), get_write_buffer_size(), get_extra_info() and the sendfile() fallback after close; done means these paths no longer raise the reported AttributeError and the fallback reports the expected connection error.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Bug report
If a protocol closes its SSL transport in connection_lost(), which is a common pattern, later calls on the transport fail:
import asyncio
from test.test_asyncio import utils as tu
class Proto(asyncio.Protocol):
def connection_made(self, tr):
self.tr = tr
def connection_lost(self, exc):
self.tr.close()
self.lost.set_result(None)
async def main():
async def handler(reader, writer):
writer.close()
srv = await asyncio.start_server(handler, '127.0.0.1', 0,
ssl=tu.simple_server_sslcontext())
port = srv.sockets[0].getsockname()[1]
loop = asyncio.get_running_loop()
proto = Proto()
proto.lost = loop.create_future()
tr, _ = await loop.create_connection(
lambda: proto, '127.0.0.1', port, ssl=tu.simple_client_sslcontext())
await proto.lost
tr.write(b'x') # AttributeError: 'NoneType' object has no attribute '_write_appdata'
srv.close()
asyncio.run(main())
set_protocol(), get_write_buffer_size() and get_extra_info() fail the same way. Plain TCP transports don't have this problem.
It also breaks the loop.sendfile() fallback over SSL: if the peer disconnects mid-transfer, restore() calls set_protocol() and raises AttributeError instead of the expected connection error.
The cause is in _SSLProtocolTransport.close(). When it's called on a transport already marked closed, it sets _ssl_protocol = None. That was added in gh-98539 so the transport doesn't keep the SSL context alive, but it leaves the transport unusable.
Affects 3.11 and later.
Linked PRs
- gh-160965
- Langage dominant
- Python
- Étoiles
- 77.8k
- Forks
- 37.7k
- Merge moyen
- 17 h 24 min
- PR mergées (30 j)
- 716
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de python/cpython
-
build OS-unsupported OS-windows type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 60/100
Les mainteneurs répondent en général sous 1 jour
-
What's New in 3.12 credits the unstable C API tier to PEP 697 instead of PEP 689Peut-être pris @TheLouisMahdi l’a pris il y a 1 jour. Ouvertedocs
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
python/cpython#161078 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
OS-windows type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 1 jour
-
docs
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
python/cpython#161007 · 4 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Null dereferencing of a pointer in initconfig.cPeut-être pris @lazerg l’a pris il y a 3 jours. Ouverteinterpreter-core topic-C-API type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
python/cpython#160962 · 4 commentaires ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de python/cpython
Issues similaires
-
Import errors are swallowed: PerthImplicitWatermarker silently becomes NonePeut-être pris @JonRC l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
resemble-ai/Perth#23 ·
-
correction metadata
Difficulté 2/5 Moins d'une heure Accessibilité débutants 65/100
acl-org/acl-anthology#10753 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
earthtojake/text-to-cad#758 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 1-3 heures Accessibilité débutants 70/100
DataTalksClub/faq#545 ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 1 jour