FeishuChannel.stop leaves bot identity retry task pending
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
从 lark_oapi.channel.channel 中的 _start_bot_identity_retry_loop()、schedule() 和 stop() 开始。复现长延迟重试,然后添加生命周期回归测试,验证 stop() 会取消并清空重试 future,且不会出现 pending-task 警告。完成标准是 bot-identity 重试由 channel 跟踪,并且关闭时不留下待处理任务。
由索引模型根据 Issue 内容生成。
描述
Affected version
lark-oapi1.7.3- Default branch commit:
0b9e6e48b74bb4b34462fc67b7e738b27e73e697 - Reproduced on Python 3.13.13 and 3.14.4 on Windows
Problem
FeishuChannel._start_bot_identity_retry_loop() submits _bot_identity_retry_loop() with asyncio.run_coroutine_threadsafe() but discards the returned future. Unlike FeishuChannel.schedule(), this path never adds the future to _bg_tasks.
FeishuChannel.stop() only cancels futures in _bg_tasks before stopping and closing the background event loop. A sleeping bot-identity retry therefore survives shutdown as a pending task.
Minimal reproduction
import asyncio
import time
from unittest.mock import patch
from lark_oapi.channel import FeishuChannel
channel = FeishuChannel(app_id="cli_x", app_secret="s")
channel._ensure_bg_loop()
channel._BOT_IDENTITY_RETRY_DELAYS_S = (3600,)
captured = []
original = asyncio.run_coroutine_threadsafe
def capture(coro, loop):
future = original(coro, loop)
captured.append(future)
return future
with patch(
"lark_oapi.channel.channel.asyncio.run_coroutine_threadsafe",
side_effect=capture,
):
channel._start_bot_identity_retry_loop()
time.sleep(0.05)
print(captured[0] in channel._bg_tasks) # False
channel.stop()
print(captured[0].done(), captured[0].cancelled()) # False False
At interpreter shutdown:
Task was destroyed but it is pending!
task: <Task pending ... coro=<FeishuChannel._bot_identity_retry_loop() ...>>
The same pending-task warning appeared after the native test suite on both Python 3.13 and 3.14.
Expected behavior
stop() should cancel and drain every task owned by the channel background loop, including the bot-identity retry task, without a pending-task warning.
Impact
A startup identity lookup failure schedules a retry that can sleep for up to an hour. Stopping or reconnecting the channel during that delay closes its loop while the retry is still pending. This produces noisy shutdown diagnostics and leaves channel-owned work outside the documented lifecycle tracking.
Suggested implementation
Route this coroutine through the existing schedule() helper, or explicitly track its future in _bg_tasks, then add a lifecycle regression test that starts a long-delay retry, calls stop(), and verifies the future is cancelled and no pending task remains.
I searched open and closed issues, all pull request states, and repository history for bot identity retry, Task was destroyed, _start_bot_identity_retry_loop, and related lifecycle terms. I did not find an existing report or competing fix. Open PRs #139, #144, and #151 touch adjacent client/channel lifecycle code but do not track or cancel this retry future.
- 主要语言
- Python
- 星标
- 559
- 派生
- 102
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
larksuite/oapi-sdk-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 67/100
larksuite/oapi-sdk-python#163 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
larksuite/oapi-sdk-python#162 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 94/100
larksuite/oapi-sdk-python#161 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
larksuite/oapi-sdk-python#160 ·
-
难度 1/5 1-3 小时 新手友好度 88/100
larksuite/oapi-sdk-python#145 ·
查看 larksuite/oapi-sdk-python 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
stephrobert/dsoxlab#238 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
sublimehq/package_control#1780 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 70/100
nwg-piotr/nwg-displays#145 ·