Skip to content

fix(common): restore signature user data subscriptions after a reconnect - #581

Merged
alplabin merged 1 commit into
binance:release_common_v4.7.0from
Amadeus-22:fix-578-user-data-resubscribe
Oct 23, 2026
Merged

alplabin merged 1 commit into
binance:release_common_v4.7.0from
Amadeus-22:fix-578-user-data-resubscribe

Conversation

@Amadeus-22

Copy link
Copy Markdown
Contributor

Fixes #578.

Problem

A user data subscription made with userDataStream.subscribe.signature is not restored when a WebSocket API connection reconnects (planned 24h renewal, serverShutdown, or failure). reconnect() only resubscribes user streams on the session.logon path, so after a reconnect the new connection has no subscription and execution reports and balance updates stop, with no error.

Change

  • The signature subscribe request is kept per connection, keyed by the subscriptionId the server returned (without id, timestamp or signature).
  • After a reconnect it is signed again with a fresh timestamp, sent on the new connection, and the reply is awaited.
  • Callbacks, response types and the RequestStreamHandle move to the subscriptionId returned on the new connection, so handle.on() and handle.unsubscribe() keep working.
  • Streams unsubscribed before the reconnect (handle.unsubscribe(), userDataStream.unsubscribe with or without subscriptionId) are not restored, and a connection that is closed for good forgets its stored requests.
  • If the resubscribe fails or times out, an error connection event is emitted and the stream is dropped.
  • The session.logon path no longer sends userDataStream.subscribe for signature subscriptions, and no longer drops them when the re-logon fails.

Tests

Added TestSignatureUserDataResubscribe in common/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 emits error, and logon and signature subscriptions are not mixed. 5 of them fail on master. pytest tests in common/ passes (410), also together with #580. ruff check is clean; the new code is formatted with black.

🤖 Generated with Claude Code

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>
@alplabin
alplabin changed the base branch from master to release_common_v4.7.0 October 23, 2026 09:41
@alplabin
alplabin merged commit a4cd8bf into binance:release_common_v4.7.0 Oct 23, 2026
@Amadeus-22
Amadeus-22 deleted the fix-578-user-data-resubscribe branch October 23, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebSocket API: signature user data subscription is lost after reconnect

2 participants