Skip to content

Client handles abort signals incorrectly in high availability configuration #251

Closed
@jonatansberg

Description

@jonatansberg

Description

Using SearchClient with the cluster configuration suggested by the docs (both LB + nodes) together with an AbortSignal causes the client to bypass the LB and call the nodes directly if/when the signal fires.

Steps to reproduce

  • Use SearchClient in cluster configuration suggested by the docs (both LB + nodes)
  • Pass an abort controller signal in SearchOptions
let controller: AbortController | null = null;
const client = new SearchClient({
  nearestNode: { host: 'xxx.a1.typesense.net', port: 443, protocol: 'https' },
  nodes: [
    { host: 'xxx-1.a1.typesense.net', port: 443, protocol: 'https' },
    { host: 'xxx-2.a1.typesense.net', port: 443, protocol: 'https' },
    { host: 'xxx-3.a1.typesense.net', port: 443, protocol: 'https' },
  ],
  apiKey: '<API_KEY>',
  connectionTimeoutSeconds: 2
});

function search(q: string) {
  if (controller) controller.abort();
  controller = new AbortController();
  const abortSignal = controller.signal;

  client
    .collections('<collection>')
    .documents()
    .search(
      { 
        q
        // ...rest of query
      },
      { abortSignal }
    );
}

Expected Behavior

Request is aborted when signal fires.

Actual Behavior

Request is aborted, and this makes the client cycle through the nodes. Initially from the LB -> first node, and then proceeding through the nodes in order every time a request is interrupted, wrapping around to the first one at the end.

Metadata

Typesense Version: 1.8.2, 1.7.2
OS: MacOS

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