Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit bbcf777. Configure here.
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection: The changes to BackgroundBridge.js are bug fixes focused on:
Impact Assessment:
Tags selected:
Dependent tags verified:
Performance Test Selection: |
|
|
✅ E2E Fixture Validation — Schema is up to date |




Description
BackgroundBridgesubscribes to seven controller messenger events in its constructor butonDisconnect()only tore down three. After a session disconnects, the leaked subscriptions kept firing — emittingchainChanged/accountsChangednotifications and lock/unlock events to dead sessions.Root causes of the four leaks:
SelectedNetworkController:stateChange— missing fromonDisconnect()entirely.KeyringController:lock/unlock— subscribed withthis.onLock.bind(this)/this.onUnlock.bind(this)inline, so each call produced a fresh reference that couldn't be matched for unsubscription.PermissionController:stateChange— subscribed with an anonymous arrow function, same reference-matching problem.Fix:
this._handleLock,this._handleUnlock,this._handlePermissionControllerStateChange) in the constructor and pass them to bothsubscribeandtryUnsubscribe.tryUnsubscribecalls for all four events inonDisconnect().onDisconnect()idempotent: early-return onthis.disconnected, and convert the existing CAIPunsubscribecalls (which throw on a missing sub) totryUnsubscribe.onDisconnectis invoked from ~6 call sites and could previously throw on a second call.Affects both SDKConnectV2 and WalletConnect since they share this class.
Changelog
CHANGELOG entry: Fixed a subscription leak in
BackgroundBridgewhere disconnected SDK and WalletConnect sessions could continue to receive network, account, permission, and lock/unlock notifications.Related issues
Fixes: WAPI-1367
Manual testing steps
Screenshots/Recordings
N/A — no UI changes.
Before
After
Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleN/A — subscription-teardown fix, no user-visible flow or new instrumented operations.
For performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist
Note
Medium Risk
Changes connection teardown logic for provider sessions; mistakes could drop needed notifications or leave subscriptions around, impacting WalletConnect/SDK session behavior.
Overview
Fixes
BackgroundBridgeevent-subscription leaks by using stable handler references forKeyringControllerlock/unlock andPermissionController:stateChange, and by adding missing teardowns (includingSelectedNetworkController:stateChange) inonDisconnect().Makes
onDisconnect()idempotent (early-return when already disconnected) and switches CAIP-related unsubscriptions totryUnsubscribeto avoid errors on repeated teardown calls. Adds focused unit tests asserting correct handler-based unsubscription and safe repeatedonDisconnect()invocation.Reviewed by Cursor Bugbot for commit e4e1440. Bugbot is set up for automated code reviews on this repo. Configure here.