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

FeishuChannel.stop leaves bot identity retry task pending

未关闭 适合新手
#159 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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-oapi 1.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

贡献指南

这个仓库没有索引到贡献指南

从这里开始

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

larksuite/oapi-sdk-python 的其他 Issue

查看 larksuite/oapi-sdk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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