typesense / typesense-instantsearch-adapter

A JS adapter library to build rich search interfaces with Typesense and InstantSearch.js
MIT License
410 stars 63 forks source link

Hitting a time out error 'Error: 500 - Request timed out.' but only client side #220

Open eric-brace opened 1 month ago

eric-brace commented 1 month ago

Description

Using typesense-instantsearch-adapter and for longer running queries getting a 500 timed out error after 5 seconds. It seems to match the timeout here int he advanced settings for algolia https://www.algolia.com/doc/api-reference/api-methods/configuring-timeouts/

For more context we're using Remix and don't have any timeouts set there. The response actually returns from the multi_search network call but the browser seems to cancel the request before it can be used by the application.

We're also using onStateChange in component. Wondering if there's a timeout setting somewhere that we've missed or if anyone has come across this before.

Typesense adapter configuration is set to 20 seconds.

server: {
      apiKey: ak,
      connectionTimeoutSeconds:20,
      nodes: [
        {
          host: '<host_url>',
          path:"/typesense",
          port: 443,
          protocol: 'https',
        },
      ],
    },

Steps to reproduce

Screenshot 2024-10-07 at 18 13 34 Screenshot 2024-10-07 at 18 13 59

Expected Behavior

Expect request to our typesense server to not timeout after 5 seconds. Using curl there's no timeout.

Actual Behavior

5 second timeout.

Metadata

Typesense Version: "typesense-instantsearch-adapter": "^2.8.0"

OS:

jasonbosco commented 1 month ago

Do you have a reverse proxy / backend that is proxying requests between the browser and Typesense? If so, I suspect that the timeout might be coming from that system.

In the adapter itself, connectionTimeoutSeconds is the only timeout configuration.

eric-brace commented 1 month ago

Is there a way to have the adapter limit the number of searches per multisearch call? Or to default to only doing one search?

karolzdebel commented 1 week ago

@jasonbosco I don't think it has to do with the reverse proxy since we can reproduce in a local environment where we're communicating directly with a local Typesense server. Some of the multi-search results return a 500 and an error message indicating a timeout. Other multi-search results part of the same request succeed.

I cannot reproduce when embeddings aren't being used. Could it be that the timeout stems from Typesense's network requests to Open AI or something else involving embeddings?

Note: I'm reproducing in Postman by sending multi-search requests "manually"

{
    "code": 500,
    "error": "Request timed out."
}
jasonbosco commented 1 week ago

Ah with remote embedding, there is a separate timeout on the server side when making calls out to remote embedding services. These parameters are documented here: https://typesense.org/docs/27.1/api/vector-search.html#remote-embedding-api-parameters

The default is not 5s though, it's 30s.

karolzdebel commented 1 week ago

@jasonbosco Setting the remote_embedding_timeout_ms to 30s fixed the issue based on my testing so far. Can you verify the default is actually 30s and not 5s? Might be a bug in the docs or in the code.