Skip to content

Error with websocket reconnectionΒ #547

@demora33

Description

@demora33

[REQUIRED] Environment

  • Runtime: Node.js (server-side)
  • Alchemy SDK version: 3.6.5

[REQUIRED] Describe the problem

With Alchemy SDK v3.6.5 we are seeing intermittent uncaught exceptions during WebSocket reconnections. The error originates inside the SDK and is not related to application code or ethers.

Error:

TypeError: Cannot read properties of undefined (reading 'subscription')

Failing location:

alchemy-sdk/src/api/alchemy-websocket-provider.ts:500:39

Failing line:

const physicalId = message.params.subscription;

During reconnection, a message can arrive before subscriptions are fully re-established. In that case message.params is undefined, but handleMessage accesses it without validation, causing an uncaught exception.

How to reproduce

  1. Use Alchemy SDK v3.6.5 with WebSocket subscriptions.
  2. Let the WebSocket disconnect and auto-reconnect.
  3. A message is received during the reconnection window.
  4. handleMessage runs and throws the error above.

This is intermittent and timing-related, but reproducible under network instability.

Relevant code or sample repro

No minimal repro available. Observed in production.

Suggested defensive fix:

if (!message.params || !message.params.subscription) {
  return;
}

This would prevent crashes when out-of-order or malformed messages arrive during reconnection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions