redis/node-redis · critical · Error

couldn't connect to any sentinels

Error message

couldn't connect to any sentinels

What it means

The companion of [88]: in `getMasterNode()`, if the loop never set `connected = true` (no sentinel could be reached at all), the method throws 'couldn't connect to any sentinels'. It is the pure connectivity-failure branch, distinct from the enumeration-failure branch.

Solutions

  1. Make at least one sentinel reachable (host/port/DNS).
  2. Correct `sentinelClientOptions` auth and TLS.
  3. Add redundant sentinel seeds.
  4. Check the sentinel process health and network path.
Defensive patterns

Strategy: retry

Try / catch

async function getMasterWithRetry(sentinel: { getMasterNode(): Promise<unknown> }, attempts = 5) {
  for (let i = 0; i < attempts; i++) {
    try { return await sentinel.getMasterNode(); }
    catch (e) {
      if (String(e).includes("couldn't connect to any sentinels") && i < attempts - 1) {
        await new Promise(r => setTimeout(r, 500 * 2 ** i)); continue;
      }
      throw e;
    }
  }
}

Prevention

When it happens

Trigger: Calling `getMasterNode()` when every sentinel root node fails to connect. The `connected` flag stays false for the whole loop.

Common situations: All sentinels down; wrong host/port in rootNodes; auth failure (bad password) on every sentinel; network partition; TLS handshake failure.

Related errors


AI-assisted analysis of redis/node-redis@90fd0652bc (2026-08-11). Data as JSON: /api/errors/ddbddb5e4168a320. Report an issue: GitHub.

Appendix: source

Thrown at packages/client/lib/sentinel/index.ts:1761

      try {
        const masterData = await client.sentinel.sentinelMaster(this.options.name);

        const master = parseNode(masterData);
        if (master === undefined) {
          continue;
        }

        return master;
      } finally {
        client.destroy();
      }
    }

    if (connected) {
      throw new Error("Master Node Not Enumerated");
    }

    throw new Error("couldn't connect to any sentinels");
  }

  async getMasterClient() {
    const master = await this.getMasterNode();
    const socket = getMappedNode(master.host, master.port, this.options.nodeAddressMap);
    return RedisClient.create({
      ...this.options.nodeClientOptions,
      socket: {
        ...this.options.nodeClientOptions?.socket,
        host: socket.host,
        port: socket.port
      }
    });
  }

  async getReplicaNodes() {
    let connected = false;

View on GitHub (pinned to 90fd0652bc)