.Net client socket error after many inserts

I'm trying to create documents in Elastic with the .Net client. (7.17.1 on server 8.1.3)
This works, but on the first sync I have many documents and after a lot of successul inserts the elastic client stops working.

I create the client like this only once:

var node = new Uri(config.ElasticHost);
var pool = new SingleNodeConnectionPool(node);
var elasticSettings = new ConnectionSettings(pool)
    .CertificateFingerprint(config.ElasticFingerprint)
    .BasicAuthentication(config.ElasticUser, config.ElasticPassword)
    .DefaultMappingFor...
    .EnableDebugMode()
    .PrettyJson();
_elasticClient = new ElasticClient(elasticSettings);

Then for each new document I use this:

private async Task<bool> UpdateOrInsert<T>(T item) where T : ElasticDocument
{
    
    var response = await _elasticClient.IndexDocumentAsync<T>(item);
    if (!response.IsValid)
    {
        _logger.LogError(response.OriginalException.Message);
        _logger.LogError(response.DebugInformation);
        return false;
    }
    return true;
}

After a while I get the error below.
What could cause this? The server is not broken after this. I can just connect again.
Seems like the client stops working after a while?

Invalid NEST response built from a unsuccessful () low level call on PUT: /productlink-dev/_doc/LC-7-1085-DUMMY_1201G6302000_ST30?pretty=true&error_trace=true
# Audit trail of this API call:
 - [1] BadRequest: Node: https://xx.xx.xx.xx:9200/ Took: 00:00:19.2788193
# OriginalException: System.Net.Http.HttpRequestException: An error occurred while sending the request.
 ---> System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond..
 ---> System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
   at System.Net.Security.SslStream.EnsureFullTlsFrameAsync[TIOAdapter](TIOAdapter adapter)
   at System.Net.Security.SslStream.ReadAsyncInternal[TIOAdapter](TIOAdapter adapter, Memory`1 buffer)
   at System.Net.Http.HttpConnection.InitialFillAsync(Boolean async)
   at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Elasticsearch.Net.HttpConnection.RequestAsync[TResponse](RequestData requestData, CancellationToken cancellationToken)
# Request:
{stripped}
# Response:

# TCP states:
  Established: 323
  TimeWait: 7
  CloseWait: 1

# ThreadPool statistics:
  Worker:
    Busy: 1
    Free: 32766
    Min: 16
    Max: 32767
  IOCP:
    Busy: 1
    Free: 999
    Min: 16
    Max: 1000

Update:
I tried with BulkAll but now I get Invalid documents without an error.

The BulkAll method works after adding EnableApiVersioningHeader.

But after a while I get this error:

 BulkAll halted after PipelineFailure.BadRequest from _bulk and exhausting retries (2)
Elastic.Transport.TransportException: BulkAll halted after PipelineFailure.BadRequest from _bulk and exhausting retries (2)
   at Nest.BlockingSubscribeExtensions.WaitOnObservable[TObservable,TObserve,TObserver](TObservable observable, TimeSpan maximumRunTime, Func`3 factory)
   at Nest.BlockingSubscribeExtensions.Wait[T](BulkAllObservable`1 observable, TimeSpan maximumRunTime, Action`1 onNext)

I tried recreating the elastic client on each run but that makes it worse. It seems this client is not yet ready for Elastic 8. I tried the alpha version but get the same errors.

Hi @r03. Based on the exceptions which are down in the .NET networking layer, this appears to be a networking issue preventing some of the requests succeeding. How many documents succeed before failure? I've been testing with millions of documents, against an Elastic Cloud 8.x deployment with no issues from 7.17 client or 8.0 alpha. How are you running ES? You may need to enable some logging on the server to verify if the requests are received or any failures are logged there.

Yes, it seems to work fine when running the same elastic server version locally.
I guess there must be an error on the https level somewhere.

image