Skip to content

Commit d4900cf

Browse files
committed
Handle exceptions during product check
1 parent fc71404 commit d4900cf

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/Elastic.Clients.Elasticsearch.Shared/Client/ElasticsearchClient.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ private ValueTask<TResponse> DoRequestCoreAsync<TRequest, TResponse, TRequestPar
145145
where TRequestParameters : RequestParameters, new()
146146
{
147147
// The product check modifies request parameters and therefore must not be executed concurrently.
148+
// We use a lockless CAS approach to make sure that only a single product check request is executed at a time.
149+
// We do not guarantee that the product check is always performed on the first request.
148150

149151
var productCheckStatus = Interlocked.CompareExchange(
150152
ref _productCheckStatus,
@@ -174,6 +176,26 @@ ValueTask<TResponse> SendRequest()
174176
}
175177

176178
async ValueTask<TResponse> SendRequestWithProductCheck()
179+
{
180+
try
181+
{
182+
return await SendRequestWithProductCheckCore().ConfigureAwait(false);
183+
}
184+
catch
185+
{
186+
// Re-try product check on next request
187+
188+
Interlocked.CompareExchange(
189+
ref _productCheckStatus,
190+
(int)ProductCheckStatus.NotChecked,
191+
(int)ProductCheckStatus.InProgress
192+
);
193+
194+
throw;
195+
}
196+
}
197+
198+
async ValueTask<TResponse> SendRequestWithProductCheckCore()
177199
{
178200
// Attach product check header
179201

0 commit comments

Comments
 (0)