Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đã đóng
#49,131 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@EldertGrootenboer đang làm issue này rồi.

Từ ngày 23/9/2026.

  • #49159 của @EldertGrootenboer — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
azure, python
Lĩnh vực
backend, networking

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
5.6k
Fork
3.4k
Merge trung bình
2 ngày 10 giờ
Pull request đã merge (30 ngày)
209

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Azure/azure-sdk-for-python

Tất cả issue của Azure/azure-sdk-for-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.