Skip to content

[bug]: TCP ports exhaution or stale DNS resolution #3681

@fredericDelaporte

Description

@fredericDelaporte

Description

The default SearchClient implementation for the .Net client does not follow the HttpClient guidelines and exposes the user to either exhausting the TCP port of the computer or have stale DNS resolution in case of a changes in the Algolia DNS.

  • An application using the SearchClient by instantiating it for each query will risk causing TCP port exhaustion on the computer on which it runs.
  • An application using it as a singleton will miss any DNS update that may occur on Algolia side.

(And there is no guidance on the "Get started" page about the intended lifecycle for the client.)

We can implement our own Algolia IHttpRequester as a work around, but it would be better for the default implementation to be reliable "out of the box", at least with some usage guidelines.

Language

CSharp

Client

Search

Steps to reproduce

Check the code:
https://github.com/algolia/api-clients-automation/blob/265d3923b79c2329e965dc6bcd34b5134ddcd7cf/clients/algoliasearch-client-csharp/algoliasearch/Http/AlgoliaHttpRequester.cs#L21C1-L25C8

  private readonly HttpClient _httpClient = new(
    new TimeoutHandler
    {
      InnerHandler = new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip }
    });

So, that is a HttpClient creation, ultimately, for each instance of SearchClient, using neither a SocketsHttpHandler with a configured PooledConnectionLifetime nor an IHttpClientFactory. The former is required for using the SearchClient as a singleton while avoiding stale DNS resolution. The later is required for using the SearchClient by instantiating it for each usage while avoiding TCP port exhaustion.

Relevant log output

No response

Self-service

  • I'd be willing to fix this bug myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions