Skip to content

Commit d26b65e

Browse files
committed
fixed aggregate exceptions bubling out as suppose to maxretryexceptions
1 parent 652732e commit d26b65e

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

src/Elasticsearch.Net/Connection/RequestHandlers/RequestHandler.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ private ElasticsearchResponse<T> ReturnStreamOrVoidResponse<T>(
6565
{
6666
// If the response never recieved a status code and has a caught exception make sure we throw it
6767
if (streamResponse.HttpStatusCode.GetValueOrDefault(-1) <= 0 && streamResponse.OriginalException != null)
68-
throw streamResponse.OriginalException;
68+
{
69+
streamResponse.OriginalException.RethrowKeepingStackTrace();
70+
return null; //wont be hit
71+
}
6972

7073
// If the user explicitly wants a stream returned the undisposed stream
7174
if (typeof(Stream).IsAssignableFrom(typeof(T)))

src/Elasticsearch.Net/Connection/RequestHandlers/RequestHandlerAsync.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private Task<ElasticsearchResponse<T>> HandleStreamResponse<T>(Task<Elasticsearc
205205
//If we are not using any pooling and we see an exception we rethrow
206206
if (!requestState.UsingPooling && t.IsFaulted && t.Exception != null && maxRetries == 0)
207207
{
208-
t.Exception.RethrowKeepingStackTrace();
208+
t.Exception.Flatten().InnerException.RethrowKeepingStackTrace();
209209
return null; //won't be hit
210210
}
211211

src/Elasticsearch.Net/Connection/RequestHandlers/RequestHandlerBase.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ protected void ThrowMaxRetryExceptionWhenNeeded<T>(TransportRequestState<T> requ
141141

142142
//When we are not using pooling we forcefully rethrow the exception
143143
if (!requestState.UsingPooling && innerException != null && maxRetries == 0)
144-
throw innerException;
144+
{
145+
innerException.RethrowKeepingStackTrace();
146+
return;
147+
}
145148

146149
var exceptionMessage = tookToLong
147150
? CreateTookTooLongExceptionMessage(requestState, innerException)

src/Elasticsearch.Net/Connection/Transport.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ IList<Uri> ITransportDelegator.Sniff(ITransportRequestState ownerState = null)
201201
using (response.Response)
202202
{
203203
return Sniffer.FromStream(
204-
response,
205-
response.Response,
206-
this.Serializer,
204+
response,
205+
response.Response,
206+
this.Serializer,
207207
this.Connection.AddressScheme
208208
);
209209
}
@@ -265,7 +265,7 @@ bool ITransportDelegator.TookTooLongToRetry(ITransportRequestState requestState)
265265
var timeout = this.Settings.MaxRetryTimeout.GetValueOrDefault(TimeSpan.FromMilliseconds(this.Settings.Timeout));
266266
var startedOn = requestState.StartedOn;
267267
var now = this._dateTimeProvider.Now();
268-
268+
269269
//we apply a soft margin so that if a request timesout at 59 seconds when the maximum is 60
270270
//we also abort.
271271
var margin = (timeout.TotalMilliseconds / 100.0) * 98;
@@ -348,7 +348,17 @@ public Task<ElasticsearchResponse<T>> DoRequestAsync<T>(string method, string pa
348348
{
349349
using (var requestState = new TransportRequestState<T>(this.Settings, requestParameters, method, path))
350350
{
351-
return this._requestHandlerAsync.RequestAsync(requestState, data);
351+
return this._requestHandlerAsync.RequestAsync(requestState, data)
352+
.ContinueWith<ElasticsearchResponse<T>>(t =>
353+
{
354+
if (t.IsFaulted && t.Exception != null)
355+
{
356+
t.Exception.Flatten().InnerException.RethrowKeepingStackTrace();
357+
return null; //won't be hit
358+
}
359+
360+
return t.Result;
361+
});
352362
}
353363
}
354364
}

0 commit comments

Comments
 (0)