WebSocket API: signature user data subscription is lost after reconnect
関連するプルリクエストがすでにマージされています。
- #581 @Amadeus-22 による — マージ済み
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
- 領域
- backend, networking
調査の方向性
Start with common/src/binance_common/websocket.py and reconnect() around line 916, then follow how userDataStream.subscribe.signature stores subscription state and how callbacks are keyed by subscriptionId. Reproduce with the described local aiohttp WebSocket server and the failing pytest mentioned in the issue. Done means signature subscriptions are restored after reconnect, callbacks use the new subscription ID, and resubscribe failures emit an error.
索引モデルが issue の本文から書いたものです。
説明
Summary
A user data subscription made with userDataStream.subscribe.signature (no session.logon) is not restored when the WebSocket API connection reconnects, including the planned reconnect before the 24h limit and after serverShutdown. The bot stops receiving execution reports and balance updates, and no event or error is raised.
Where
common/src/binance_common/websocket.py, reconnect() (line 916 at a54ec0b): user streams are only resubscribed inside if connection.session_logon_request and self.configuration.session_re_logon. A signature subscription stores no logon request, so nothing is sent on the new connection, and user_stream_connections still points to the closed one.
Reproduction
Local aiohttp WebSocket server, no Binance network:
userDataStream.subscribe.signatureon a WS API client in single mode; the server replies withsubscriptionId: 0.- The server sends
serverShutdown(or the reconnect timer fires). - The client opens connection 2, but the server receives no subscribe request on it, and events pushed there never reach the callback.
I have this as a failing pytest and can share it.
Suggested fix
- Store the subscribe request per subscription, as
session_logon_requestis stored, and replay it, re-signed with a fresh timestamp, after reconnect. - Remap the callbacks to the
subscriptionIdreturned on the new connection instead of assuming it is unchanged._resubscribe_user_streamson the logon path assumes the same id and does not await the reply. - If the resubscribe fails, emit an
errorevent so the application can react.
I'm happy to open a PR along these lines if this approach works for you.
Related, found while testing (each has a failing test, I can open separate issues or PRs)
- A reply that arrives after
asyncio.wait_for(future, 20)timed out raisesInvalidStateErrorinreceive_loop(future.set_resulton a cancelled future), which ends the loop: the connection stays open but nothing else is received. Fix: skip futures that aredone()and pop the id on timeout. - In pool mode,
subscribe_user_dataregisters the callback on the next connection in the round robin, not the one that sent the subscribe, so events are dropped. send_requestretries signedDELETE(order cancel) after aReadTimeout; the first request was already delivered, so the retry returns-2011 Unknown order sent.for an order that was cancelled. Retrying only on connect errors and 5xx would avoid it.
- 主要言語
- Python
- スター
- 3k
- フォーク
- 712
- 平均マージ
- 1日 13時間
- マージ済み PR(30日)
- 9
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
binance/binance-connector-python のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
binance/binance-connector-python#570 · コメント 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 15/100
binance/binance-connector-python#575 · コメント 1 件 ·
-
[Bug] Response models declare numeric fields as strict `str`, causing silent fallback of `.data()` to raw dict (simple-earn & staking)対応中かも @Tyagiquamar が 35 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
binance/binance-connector-python#553 · コメント 2 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
binance/binance-connector-python#464 · コメント 1 件 · リアクション 5 件 ·
binance/binance-connector-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
foxglove/mcap#1907 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
namespace operations
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
EclipseFdn/open-vsx.org#14623 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
developmentseed/titiler-cmr#261 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
andrewyng/openworker#774 ·
メンテナーはふだん 1 日以内に返信
-
aggfuncオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
worldbank/blackmarblepy#160 ·