You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Explanation
This PR releases **@metamask/[email protected]** with significant
improvements to WebSocket reconnection reliability and robustness for
real-time balance updates.
### Current State & Problems Addressed
The previous WebSocket implementation had several reliability issues:
1. **Duplicate reconnection timers** could be created when multiple
events triggered reconnects simultaneously, leading to memory leaks and
inflated reconnect attempt counters
2. **Rapid reconnection loops** could occur when the server accepted
connections but immediately closed them
3. **Race conditions** in reconnection scheduling could bypass
exponential backoff, causing aggressive retry behavior
4. **Manual subscription cleanup** was fragile when recovering from
subscription issues or orphaned subscriptions
### Solution
This release introduces robust reconnection logic with the following
improvements:
#### 1. **Idempotent Reconnection Scheduling**
- Prevents duplicate reconnection timers from being created
- Checks if a reconnect is already scheduled before creating a new timer
- Eliminates memory leaks from orphaned timers
- Prevents unnecessary growth of reconnect attempt counters
#### 2. **Stable Connection Timer**
- Connection must remain stable for 10 seconds before resetting
reconnect attempts
- Prevents rapid reconnection loops when server accepts then immediately
closes connections
- Provides grace period for connection stability before declaring
success
#### 3. **Force Reconnection Method**
- New `forceReconnection()` public API for controlled subscription state
cleanup
- Performs a controlled disconnect-then-reconnect sequence with
exponential backoff
- Useful for recovering from subscription/unsubscription issues and
cleaning up orphaned subscriptions
- Exposed via `BackendWebSocketService:forceReconnection` messenger
action
#### 4. **Improved Error Handling**
- Always schedules reconnect on connection failure (exponential backoff
prevents aggressive retries)
- Removes redundant schedule calls from error paths
- Better logging throughout for easier debugging
#### 5. **Better State Management**
- `disconnect()` now properly resets reconnect attempts counter
- Fixed race condition in `connect()` that could bypass exponential
backoff
- More predictable state transitions
### Technical Details
**Reconnection Behavior:**
- Uses Cockatiel's exponential backoff with decorrelated jitter to
prevent thundering herd
- Initial delay: 1000ms, max delay: 30000ms
- Backoff sequence resets only after 10 seconds of stable connection
- Automatic reconnect on unexpected disconnects, stays disconnected on
manual disconnects
**Breaking Changes:**
- `AccountActivityService` messenger allowed actions updated: removed
`BackendWebSocketService:disconnect`, added
`BackendWebSocketService:forceReconnection`
### Impact
This improves the reliability of real-time balance updates across
MetaMask Extension and Mobile by:
- ✅ Preventing connection thrashing and resource exhaustion
- ✅ Providing graceful recovery from network instability
- ✅ Eliminating memory leaks from reconnection logic
- ✅ Offering controlled subscription cleanup via `forceReconnection()`
- ✅ Enabling better monitoring with improved logging
## References
- Related to the broader WebSocket balance update initiative for
MetaMask Mobile
- Fixes#6861 - WebSocket reconnection improvements
## Checklist
- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by updating changelogs
for packages I've changed, highlighting breaking changes as necessary
- [ ] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes (MetaMask Extension and Mobile
updated)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Releases `@metamask/[email protected]` with robust WebSocket
reconnection and updates dependent packages/peer deps
(`assets-controllers@83`, `bridge-controller@55`,
`bridge-status-controller@55`); bumps monorepo version to 638.0.0.
>
> - **Core Backend**
> - Release `@metamask/[email protected]` with improved, idempotent WS
reconnection, stable-connection timer, `forceReconnection()` API,
logging and error‑handling tweaks.
> - BREAKING: `AccountActivityService` messenger actions updated (remove
`disconnect`, add `BackendWebSocketService:forceReconnection`).
> - **Assets**
> - `@metamask/[email protected]`: BREAKING peer dep bump to
`@metamask/core-backend@^3.0.0`.
> - **Bridge**
> - `@metamask/[email protected]`: BREAKING peer/dev dep bump to
`@metamask/assets-controllers@^83.0.0`.
> - `@metamask/[email protected]`: BREAKING peer/dev dep
bump to `@metamask/bridge-controller@^55.0.0`.
> - **Monorepo**
> - Bump root version to `638.0.0`; update changelogs and package
versions accordingly.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
54996e2. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Copy file name to clipboardExpand all lines: packages/core-backend/CHANGELOG.md
+5-2Lines changed: 5 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
8
8
## [Unreleased]
9
9
10
+
## [3.0.0]
11
+
10
12
### Added
11
13
12
14
- Add `forceReconnection()` method to `BackendWebSocketService` for controlled subscription state cleanup ([#6861](https://github.com/MetaMask/core/pull/6861))
@@ -21,7 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
21
23
22
24
- Bump `@metamask/base-controller` from `^8.4.1` to `^8.4.2` ([#6917](https://github.com/MetaMask/core/pull/6917))
23
25
- Update `AccountActivityService` to use new `forceReconnection()` method instead of manually calling disconnect/connect ([#6861](https://github.com/MetaMask/core/pull/6861))
0 commit comments