-
-
Couldn't load subscription status.
- Fork 253
fix(core-backend): reconnection logic #6861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,7 +80,7 @@ export type AccountActivityServiceActions = AccountActivityServiceMethodActions; | |
| export const ACCOUNT_ACTIVITY_SERVICE_ALLOWED_ACTIONS = [ | ||
| 'AccountsController:getSelectedAccount', | ||
| 'BackendWebSocketService:connect', | ||
| 'BackendWebSocketService:disconnect', | ||
| 'BackendWebSocketService:forceReconnection', | ||
| 'BackendWebSocketService:subscribe', | ||
| 'BackendWebSocketService:getConnectionInfo', | ||
| 'BackendWebSocketService:channelHasSubscription', | ||
|
|
@@ -559,16 +559,11 @@ export class AccountActivityService { | |
| * Force WebSocket reconnection to clean up subscription state | ||
| */ | ||
| async #forceReconnection(): Promise<void> { | ||
| try { | ||
| log('Forcing WebSocket reconnection to clean up subscription state'); | ||
|
|
||
| // All subscriptions will be cleaned up automatically on WebSocket disconnect | ||
| log('Forcing WebSocket reconnection to clean up subscription state'); | ||
|
|
||
| await this.#messenger.call('BackendWebSocketService:disconnect'); | ||
| await this.#messenger.call('BackendWebSocketService:connect'); | ||
| } catch (error) { | ||
| log('Failed to force WebSocket reconnection', { error }); | ||
| } | ||
| // Use the dedicated forceReconnection method which performs a controlled | ||
| // disconnect-then-connect sequence to clean up subscription state | ||
| await this.#messenger.call('BackendWebSocketService:forceReconnection'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did this because I want to fully control the reconnection via scheduleConnect |
||
| } | ||
|
|
||
| // ============================================================================= | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,27 @@ export type BackendWebSocketServiceDisconnectAction = { | |
| handler: BackendWebSocketService['disconnect']; | ||
| }; | ||
|
|
||
| /** | ||
| * Forces a WebSocket reconnection to clean up subscription state | ||
| * | ||
| * This method is useful when subscription state may be out of sync and needs to be reset. | ||
| * It performs a controlled disconnect-then-reconnect sequence: | ||
| * - Disconnects cleanly to trigger subscription cleanup | ||
| * - Schedules reconnection with exponential backoff to prevent rapid loops | ||
| * - All subscriptions will be cleaned up automatically on disconnect | ||
| * | ||
| * Use cases: | ||
| * - Recovering from subscription/unsubscription issues | ||
| * - Cleaning up orphaned subscriptions | ||
| * - Forcing a fresh subscription state | ||
| * | ||
| * @returns Promise that resolves when disconnection is complete (reconnection is scheduled) | ||
| */ | ||
| export type BackendWebSocketServiceForceReconnectionAction = { | ||
| type: `BackendWebSocketService:forceReconnection`; | ||
| handler: BackendWebSocketService['forceReconnection']; | ||
| }; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did this because I want to fully control the reconnection via scheduleConnect |
||
|
|
||
| /** | ||
| * Sends a message through the WebSocket | ||
| * | ||
|
|
@@ -159,6 +180,7 @@ export type BackendWebSocketServiceSubscribeAction = { | |
| export type BackendWebSocketServiceMethodActions = | ||
| | BackendWebSocketServiceConnectAction | ||
| | BackendWebSocketServiceDisconnectAction | ||
| | BackendWebSocketServiceForceReconnectionAction | ||
| | BackendWebSocketServiceSendMessageAction | ||
| | BackendWebSocketServiceSendRequestAction | ||
| | BackendWebSocketServiceGetConnectionInfoAction | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.