Skip to content

[bug] MaxListenersExceededWarning from WebSocket reconnection in WalletConnect relay #5534

@PaulRBerg

Description

@PaulRBerg

Link to minimal reproducible example

We're seeing this in production via Sentry on our Next.js portal app (app.sablier.com). The warning is emitted from the WalletConnect WebSocket transport when the relay at wss://relay.walletconnect.org fails and reconnects repeatedly, stacking listeners beyond the default limit of 10.

The relevant minified frame from our Sentry capture:

setMaxListeners(10)}emitError(e){let t=this.parseError(Error(e?.message||`WebSocket connection failed for host: ${I(this.url)}`));return this

This happens on page load / wallet connection without any special setup — just standard AppKit + wagmi integration in a Next.js App Router app.

Steps to Reproduce

  1. Integrate AppKit with wagmi in a Next.js app
  2. Open the app on Mobile Safari / iOS WKWebView (iPhone, iOS 18.6)
  3. Navigate to any page that initializes AppKit (e.g. an airdrops campaign page)
  4. Observe MaxListenersExceededWarning in the console and/or Sentry captures of WebSocket connection failed for host: wss://relay.walletconnect.org

Most frequently observed on Mobile Safari UI/WKWebView on iOS, but likely affects all browsers when the relay connection is unstable.

Summary

The internal WebSocket class in @walletconnect/core calls setMaxListeners(10) but appears to stack error/close/open listeners across reconnection attempts without removing stale ones. When the relay is flaky (common on mobile networks), this quickly exceeds the limit and emits MaxListenersExceededWarning.

Expected: Listeners should be cleaned up before each reconnection attempt, or the max listener count should be raised to match the actual reconnection strategy.

Actual: Listeners accumulate, triggering MaxListenersExceededWarning and polluting error monitoring with noise.

List of related npm package versions

  • @reown/appkit: 1.8.17
  • @reown/appkit-adapter-wagmi: 1.8.17
  • @reown/appkit-adapter-solana: 1.8.17
  • @walletconnect/core: 2.23.2 (transitive)
  • @walletconnect/sign-client: 2.23.2 (transitive)
  • wagmi: 2.19.5
  • viem: 2.44.2
  • next: 16 (App Router)
  • react: 19.3.0

Node.js Version

v25.6.0

Package Manager

bun@1.3.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions