From 974651520349bd64e6c4755da6f8eed1a4bd6b52 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 19 Aug 2024 13:29:42 +0200 Subject: [PATCH] Do not check product status for non-success responses (#8306) (#8308) Co-authored-by: Florian Bernd --- .../Client/ElasticsearchClient.cs | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Elastic.Clients.Elasticsearch.Shared/Client/ElasticsearchClient.cs b/src/Elastic.Clients.Elasticsearch.Shared/Client/ElasticsearchClient.cs index 26a611775d..c71b196dec 100644 --- a/src/Elastic.Clients.Elasticsearch.Shared/Client/ElasticsearchClient.cs +++ b/src/Elastic.Clients.Elasticsearch.Shared/Client/ElasticsearchClient.cs @@ -234,15 +234,19 @@ async ValueTask SendRequestWithProductCheckCore() // Evaluate product check result - var productCheckSucceeded = response.ApiCallDetails.TryGetHeader("x-elastic-product", out var values) && - values.FirstOrDefault(x => x.Equals("Elasticsearch", StringComparison.Ordinal)) is not null; + var hasSuccessStatusCode = response.ApiCallDetails.HttpStatusCode is >= 200 and <= 299; + if (hasSuccessStatusCode) + { + var productCheckSucceeded = response.ApiCallDetails.TryGetHeader("x-elastic-product", out var values) && + values.FirstOrDefault(x => x.Equals("Elasticsearch", StringComparison.Ordinal)) is not null; - _productCheckStatus = productCheckSucceeded - ? (int)ProductCheckStatus.Succeeded - : (int)ProductCheckStatus.Failed; + _productCheckStatus = productCheckSucceeded + ? (int)ProductCheckStatus.Succeeded + : (int)ProductCheckStatus.Failed; - if (_productCheckStatus == (int)ProductCheckStatus.Failed) - throw new UnsupportedProductException(UnsupportedProductException.InvalidProductError); + if (_productCheckStatus == (int)ProductCheckStatus.Failed) + throw new UnsupportedProductException(UnsupportedProductException.InvalidProductError); + } if (request.RequestParameters.RequestConfiguration is null) return response; @@ -254,6 +258,13 @@ async ValueTask SendRequestWithProductCheckCore() else if (originalHeaders is { Count: > 0 }) request.RequestParameters.RequestConfiguration.ResponseHeadersToParse = originalHeaders.Value; + if (!hasSuccessStatusCode) + { + // The product check is unreliable for non success status codes. + // We have to re-try on the next request. + _productCheckStatus = (int)ProductCheckStatus.NotChecked; + } + return response; } }