Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

已关闭
#49,131 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@EldertGrootenboer 已经在做这个了。

开始于 2026年9月23日。

  • #49159 来自 @EldertGrootenboer —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
azure, python

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
5.6k
派生
3.4k
平均合并
2 天 13 小时
30 天内合并 PR
213

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Azure/azure-sdk-for-python 的其他 Issue

查看 Azure/azure-sdk-for-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。