FeishuChannel.stop leaves bot identity retry task pending
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- backend-api-design
Research direction
Start in lark_oapi.channel.channel with _start_bot_identity_retry_loop(), schedule(), and stop(). Reproduce the long-delay retry, then add a lifecycle regression test that verifies stop cancels and drains the retry future without a pending-task warning. Done means the bot-identity retry is tracked by the channel and shutdown leaves no pending task.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 559
- Forks
- 102
- PR merge metrics
- No merged PRs in 30d
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from larksuite/oapi-sdk-python
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
larksuite/oapi-sdk-python#163 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
larksuite/oapi-sdk-python#162 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
larksuite/oapi-sdk-python#161 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
larksuite/oapi-sdk-python#160 ·
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
larksuite/oapi-sdk-python#145 ·
All issues in larksuite/oapi-sdk-python
Similar issues
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
vllm-project/vllm-metal#822 ·
Maintainers usually reply within 1 day
-
vector-store
Difficulty 1/5 1-3 hours Newbie friendliness 90/100
mem0ai/mem0#7461 · 1 comment ·
Maintainers usually reply within 1 day
-
[Bug]: chunk_span_bounds and _validated_chunk_spans reject Pydantic models ChunkSpan and AudioFileOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
BasedHardware/omi#19047 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day