Repository navigation
fix(common): restore signature user data subscriptions after a reconnect - #581
Merged
alplabin merged 1 commit intoOct 23, 2026
Conversation
A user data subscription made with userDataStream.subscribe.signature was only resubscribed on the session logon path, so after a reconnect the new connection had no subscription and events stopped silently. The subscribe request is now kept per connection and signed again on the new connection. Callbacks, response types and stream handles move to the subscriptionId returned by the server. Unsubscribed streams are not restored, a connection forgotten for good drops its stored requests, and a failed resubscribe emits an error event. Fixes binance#578 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #578.
Problem
A user data subscription made with
userDataStream.subscribe.signatureis not restored when a WebSocket API connection reconnects (planned 24h renewal,serverShutdown, or failure).reconnect()only resubscribes user streams on thesession.logonpath, so after a reconnect the new connection has no subscription and execution reports and balance updates stop, with no error.Change
subscriptionIdthe server returned (withoutid,timestamporsignature).timestamp, sent on the new connection, and the reply is awaited.RequestStreamHandlemove to thesubscriptionIdreturned on the new connection, sohandle.on()andhandle.unsubscribe()keep working.handle.unsubscribe(),userDataStream.unsubscribewith or withoutsubscriptionId) are not restored, and a connection that is closed for good forgets its stored requests.errorconnection event is emitted and the stream is dropped.session.logonpath no longer sendsuserDataStream.subscribefor signature subscriptions, and no longer drops them when the re-logon fails.Tests
Added
TestSignatureUserDataResubscribeincommon/tests/unit/test_websocket.py: the replayed request is signed with a new timestamp and events reach the callback on the new connection, the subscription id is remapped, unsubscribed streams are not restored, a closed connection forgets its requests, a failed resubscribe emitserror, and logon and signature subscriptions are not mixed. 5 of them fail onmaster.pytest testsincommon/passes (410), also together with #580.ruff checkis clean; the new code is formatted withblack.🤖 Generated with Claude Code