[BUG] subscribe_with_handler stops silently: async task can die or be collected, sync retry path exits, handler errors reconnect the stream
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 65/100
調査の方向性
Start with dapr/aio/clients/grpc/client.py#L580-L599 and dapr/clients/grpc/client.py#L628-L654, then read subscription.py#L70-L74 and the commented test in tests/clients/test_dapr_grpc_client_async.py#L424-L477. Restore async coverage and add sync and async tests for failed-then-successful reconnects and a handler that raises once. Done means subscriptions keep retrying, handler errors do not reconnect the stream, async tasks are retained and awaited on close, and caller closure remains final.
索引モデルが issue の本文から書いたものです。
説明
Expected Behavior
A subscription made with subscribe_with_handler (sync or async) keeps delivering messages to the handler until the caller closes it. If the stream drops, it reconnects, and it keeps retrying while the sidecar is unavailable. An exception raised by the handler does not tear down the stream. The returned close function stops the handler before it returns.
Actual Behavior
Links are to main at 03eebe1.
Async client: dapr/aio/clients/grpc/client.py#L580-L599
- No reference is kept to the task. It calls
asyncio.create_task(stream_messages(subscription))and discards the result. Python's docs warn that the event loop keeps only a weak reference to such a task, so it can be garbage-collected while it is still running. The subscription then stops with no error. - Any error ends the subscription. The loop catches only
StreamInactiveError. If the handler raises, or the stream raisesStreamCancelledErroror a non-retryable gRPC error, the task dies. Nothing reconnects, and the error only appears later as an "exception was never retrieved" warning. The sync client reconnects in that case. - The close function doesn't wait for the task.
close_subscription()closes the subscription but never awaits the task, so the handler can still be running afterawait close_fn()returns. - No test covers it.
test_subscribe_topic_with_handleris commented out:tests/clients/test_dapr_grpc_client_async.py#L424-L477.
Sync client: dapr/clients/grpc/client.py#L628-L654
-
The "reconnect failed, back off and retry" branch never retries.
- On a stream error the loop calls
sub.reconnect_stream(). reconnect_stream()marks the stream inactive first. Then it waits for the sidecar and callsstart().- If that wait or
start()raises, the loop sleeps 5 seconds and runscontinue. - The next
for message in subcallsnext_message(). The stream is still inactive, so that raisesStreamInactiveError, and the loop treats it as a close andbreaks.
So a sidecar outage longer than the health wait ends the subscription for good, with no error.
- On a stream error the loop calls
-
Handler errors reconnect a healthy stream. The same
except Exceptionalso catches exceptions raised byhandler_fn. One failing handler call tears down and reconnects the stream, and the message is never acked, so it is delivered again.
Steps to Reproduce the Problem
- 5: stop the sidecar while a
subscribe_with_handlersubscription is running. Keep it down for longer thanDaprHealth.wait_for_sidecarwaits, then start it again. The handler thread has exited, and no new messages reach the handler. - 6: have the handler raise for one message. The log shows a stream reconnect, and the message is delivered again.
- 2: do the same with the async client. The task ends, and no further messages are handled.
Suggested fix
Build on #1231, which makes close() final: a subscription that has been closed can no longer be reopened by a reconnect.
- Sync (5): after a failed reconnect, retry the reconnect with the backoff. Leave the loop only when the subscription was closed by the caller.
- Both (6): treat a handler exception separately from a stream error. Log it and respond with retry, instead of reconnecting the stream.
- Async (1–3):
- Keep a reference to the task.
- Handle
StreamCancelledErrorand stream errors the way the sync client does. - Have the close function await the task, with a timeout.
- Tests: restore the async handler test. Add tests for both clients: a reconnect that fails and then succeeds, and a handler that raises once.
Release Note
RELEASE NOTE: FIX subscribe_with_handler keeps retrying while the sidecar is unavailable, does not reconnect on handler errors, and the async version no longer stops silently.
- 主要言語
- Python
- スター
- 272
- フォーク
- 152
- 平均マージ
- 2日 22時間
- マージ済み PR(30日)
- 7
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
dapr/python-sdk のほかの issue
-
dapr-ext-workflow good first issue kind/enhancement P2
難易度 2/5 1〜2日 初心者へのやさしさ 72/100
dapr/python-sdk#853 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
kind/bug
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
dapr/python-sdk#1232 ·
メンテナーはふだん 1 日以内に返信
-
kind/bug
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
dapr/python-sdk#1230 ·
メンテナーはふだん 1 日以内に返信
-
dapr-ext-workflow kind/enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 78/100
dapr/python-sdk#1213 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 76/100
dapr/python-sdk#1200 ·
メンテナーはふだん 1 日以内に返信
dapr/python-sdk の issue をすべて見る
似ている issue
-
pydanty:is-working
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
pydantic/pydantic-ai#8843 ·
メンテナーはふだん 1 日以内に返信
-
breaking change enhancement server
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
sktime/sktime#11310 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信