Skip to content

Conversation

@adonesky1
Copy link
Contributor

@adonesky1 adonesky1 commented Dec 12, 2025

Fix stuck CONNECTING state in MWPTransport

Problem

The MWPTransport.connect() method could leave the underlying DappClient stuck in a CONNECTING state, causing subsequent connection attempts to fail with "Cannot connect when state is CONNECTING".

Root Causes

  1. No guard against concurrent connection calls – Multiple calls to connect() would attempt to call dappClient.connect() simultaneously
  2. Message handler leak – The 'message' handler registered during connection was never removed, causing memory leaks and duplicate handlers on reconnection
  3. Unhandled resume failures – If dappClient.resume() threw, the 'connected' event listener would hang indefinitely
  4. Missing await on onResumeSuccess – Errors from this async function were not properly caught

Changes

  • Add connectionPromise to track in-progress connections and return the existing promise on concurrent calls
  • Track and clean up the connection message handler (connectionMessageHandler) on success, failure, timeout, and disconnect
  • Handle resume() errors by removing the 'connected' listener and rejecting the promise
  • Properly await onResumeSuccess() with .catch() to surface errors

@adonesky1 adonesky1 requested a review from a team as a code owner December 12, 2025 18:01
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.

2 participants