typesense / typesense-js

JavaScript / TypeScript client for Typesense
https://typesense.org/docs/api
Apache License 2.0
393 stars 74 forks source link

Unable to make a request work #178

Closed 0x80 closed 10 months ago

0x80 commented 10 months ago

Description

import type { Client } from "typesense";
import Typesense from "typesense";
import { env } from "~/env";

let client: Client | undefined;

export function getTypesenseClient() {
  if (client) {
    return client;
  }

  client = new Typesense.Client({
    nodes: [
      {
        host: "26m1yiegxt5rpv7bp-1.a1.typesense.net",
        port: 433,
        protocol: "https",
      },
    ],
    apiKey: env.TYPESENSE_ADMIN_API_KEY,
    numRetries: 3,
    connectionTimeoutSeconds: 0,
    logLevel: "debug",
  });

  return client;
}

Then

const client = getTypesenseClient();

await client
    .collections()
    .create({
      name: "some_collection",
      fields: [{ name: "some_field", type: "string" }],
    });

I keep getting the following output:

Request #1697918148889: Performing POST request: /collections
Request #1697918148889: Nodes Health: Node 0 is Healthy
Request #1697918148889: Updated current node to Node 0
Request #1697918148889: Attempting POST request Try #1 to Node 0
Request #1697918148889: Request to Node 0 failed due to "ECONNABORTED timeout of 30000ms exceeded"
Request #1697918148889: Sleeping for 0.1s and then retrying request...
Request #1697918148889: Nodes Health: Node 0 is Unhealthy
Request #1697918148889: No healthy nodes were found. Returning the next node, Node 0
Request #1697918148889: Attempting POST request Try #2 to Node 0
Request #1697918148889: Request to Node 0 failed due to "ECONNABORTED timeout of 30000ms exceeded"
Request #1697918148889: Sleeping for 0.1s and then retrying request...
Request #1697918148889: Nodes Health: Node 0 is Unhealthy
Request #1697918148889: No healthy nodes were found. Returning the next node, Node 0
Request #1697918148889: Attempting POST request Try #3 to Node 0
Request #1697918148889: Request to Node 0 failed due to "ECONNABORTED timeout of 30000ms exceeded"
Request #1697918148889: Sleeping for 0.1s and then retrying request...
Request #1697918148889: No retries left. Raising last error
error Error: timeout of 30000ms exceeded

Metadata

Typesense Version: 1.7.2

OS: MacOS 14, Node 20

0x80 commented 10 months ago

I misspelled 443 as 433, so that was the issue :)

I think the confusing thing is that the cluster node first reports that it is healthy and later that it's unhealthy. So from these logs, my impression is that there must be something wrong with the cluster, as there is no clear error telling me that no connection could have been established.

So I think there's some room for improvement there, but feel free to close this issue

jasonbosco commented 10 months ago

I think the confusing thing is that the cluster node first reports that it is healthy

Ah, by default all nodes are assumed healthy, until we get a verifiable unhealthy response from the server.