Skip to content

HydraProvider.isConnected() silently ignores Greetings message — _connectionState never set to "CONNECTING" #817

@Crypto2099

Description

@Crypto2099

Summary

HydraProvider.isConnected() never resolves successfully because the onMessage callback has a guard that checks this._connectionState !== "CONNECTING", but _connectionState is never set to "CONNECTING". It starts as "IDLE" and the guard causes the Greetings message to be silently ignored, always resulting in a timeout.

Steps to reproduce the bug

Connect to any running Hydra node v1.2.0:

import { HydraProvider } from '@meshsdk/hydra';

const hp = new HydraProvider({
    url: 'http://localhost:4001',
    wsUrl: 'ws://localhost:4001',
});

// This always times out, even though the node sends a valid Greetings
const connected = await hp.isConnected(10000);

The WebSocket connects (logs "Hydra websocket connected"), and the Hydra node sends a valid Greetings message:

{
    "tag": "Greetings",
    "headStatus": "Idle",
    "hydraNodeVersion": "...",
    "me": {"vkey": "..."},
    "env": {...},
    "networkInfo": {...}
}

Actual Result

isConnected() always throws Error: Connection timed out: no Greetings from Hydra node.

Expected Result

Expect to see a message about the head being connected via the eventHandler.

SDK version

1.9.0-beta.99

Environment type

  • Node.js
  • Browser
  • Browser Extension
  • Other

Environment details

  • @meshsdk/hydra: 1.9.0-beta.99
  • Hydra node: ghcr.io/cardano-scaling/hydra-node:1.2.0
  • Node.js: v22.22.2
  • Network: Cardano preprod testnet

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions