Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

AmqpOverWebsocket leaks aiohttp.ClientSession instances when network disconnects during send_messages()

Chiusa
#49,131 1 commento 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@EldertGrootenboer ci sta già lavorando.

Dal 23/9/2026.

  • #49159 di @EldertGrootenboer — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
azure, python

Direzione di ricerca

Start in azure/servicebus/_pyamqp/aio_transport_async.py at connect() (reported line 451), then reproduce with the supplied async MRE while disconnecting the network before send_messages(). Trace the failed connection and retry path, and verify that every session created there is closed with no "Unclosed client session" warnings.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Service Attention Service Bus

Package

  • azure-servicebus: 7.14.3
  • azure-core: 1.41.0
  • azure-identity: 1.25.3
  • aiohttp: 3.14.3
  • Python: 3.13.7
  • OS: Windows 11 Enterprise

Describe the bug
When using the async Service Bus client with TransportType.AmqpOverWebsocket, disconnecting the network immediately before sender.send_messages() causes multiple Unclosed client session warnings.

The warnings point to azure/servicebus/_pyamqp/aio_transport_async.py, specifically line 451 in connect(), where the aiohttp.ClientSession is created.

The application uses the documented async context-manager pattern, so the Service Bus client, sender, and credential are all explicitly managed with async with.

Minimal reproduction
Execute the MRE below and disconnect the network when instructed, before the message is sent.

import asyncio
from azure.servicebus import ServiceBusMessage, TransportType
from azure.servicebus.aio import ServiceBusClient
from azure.identity.aio import DefaultAzureCredential
SERVICE_BUS_NAMESPACE = "<your_service_bus_namespace_here>"
SERVICE_BUS_QUEUE_NAME = "<your_service_bus_queue_name_here>"

async def test():
    async with DefaultAzureCredential() as cred:
        async with ServiceBusClient(
            SERVICE_BUS_NAMESPACE,
            cred,
            transport_type=TransportType.AmqpOverWebsocket,
        ) as client:
            async with client.get_queue_sender(SERVICE_BUS_QUEUE_NAME) as sender:
                print("=================== Disconnect network now ===================")
                await asyncio.sleep(15)
                print("=================== Sending... ===================")
                await sender.send_messages(ServiceBusMessage('{"ignoreMe":true}'))

asyncio.run(test(), debug=True)

Expected behaviour
When a connection attempt fails because the network has disappeared, all aiohttp.ClientSession objects created by the Service Bus transport should be closed. There should be no "Unclosed client session" errors.

Actual behaviour
Multiple aiohttp.ClientSession instances remain unclosed after the failed connection/retry sequence.

In my reproduction, four unclosed client sessions are reported.

The issue appears to occur during the failed connection/retry path rather than because the application failed to close the Service Bus client.

Additional context
Using the legacy uamqp transport (uamqp_transport=True) eliminates the problem.

Lingua principale
Python
Stelle
5.6k
Fork
3.4k
Merge medio
2g 10h
PR unite (30g)
209

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Azure/azure-sdk-for-python

Tutte le issue di Azure/azure-sdk-for-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.