Skip to content

Commit 2dae577

Browse files
committed
Show stacktraces in MaxRetryException message
1 parent 856ad81 commit 2dae577

File tree

4 files changed

+48
-44
lines changed

4 files changed

+48
-44
lines changed

src/Elasticsearch.Net/Connection/HttpConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ static HttpConnection()
2828
ServicePointManager.UseNagleAlgorithm = false;
2929
ServicePointManager.Expect100Continue = false;
3030
ServicePointManager.DefaultConnectionLimit = 10000;
31-
ServicePointManager.SetTcpKeepAlive(true, 2000, 2000);
31+
//ServicePointManager.SetTcpKeepAlive(true, 2000, 2000);
3232

3333
//WebException's GetResponse is limitted to 65kb by default.
3434
//Elasticsearch can be alot more chatty then that when dumping exceptions
3535
//On error responses, so lets up the ante.
36-
HttpWebRequest.DefaultMaximumErrorResponseLength = int.MaxValue;
36+
HttpWebRequest.DefaultMaximumErrorResponseLength = -1;
3737
}
3838

3939
public HttpConnection(IConnectionConfigurationValues settings)

src/Elasticsearch.Net/Connection/Transport.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,6 @@ public Task<ElasticsearchResponse<T>> DoRequestAsync<T>(string method, string pa
423423
var tcs = new TaskCompletionSource<ElasticsearchResponse<T>>();
424424
if (t.Exception != null)
425425
{
426-
var mr = t.Exception.InnerException as MaxRetryException;
427-
if (mr != null)
428-
throw mr;
429-
430426
tcs.SetException(t.Exception.Flatten());
431427
requestState.SetResult(null);
432428
}
@@ -436,7 +432,6 @@ public Task<ElasticsearchResponse<T>> DoRequestAsync<T>(string method, string pa
436432
requestState.SetResult(t.Result);
437433
}
438434

439-
440435
return tcs.Task;
441436
}).Unwrap()
442437
;
@@ -551,12 +546,12 @@ private static string CreateMaxRetryExceptionMessage<T>(TransportRequestState<T>
551546

552547
aggregate = aggregate.Flatten();
553548
var innerExceptions = aggregate.InnerExceptions
554-
.Select(ae => MaxRetryInnerMessage.F(ae.GetType().Name, ae.Message, "" ?? ae.StackTrace))
549+
.Select(ae => MaxRetryInnerMessage.F(ae.GetType().Name, ae.Message, ae.StackTrace))
555550
.ToList();
556551
innerException = "\r\n" + string.Join("\r\n", innerExceptions);
557552
}
558553
else
559-
innerException = "\r\n" + MaxRetryInnerMessage.F(e.GetType().Name, e.Message, "" ?? e.StackTrace);
554+
innerException = "\r\n" + MaxRetryInnerMessage.F(e.GetType().Name, e.Message, e.StackTrace);
560555
}
561556
var exceptionMessage = MaxRetryExceptionMessage
562557
.F(requestState.Method, requestState.Path, requestState.Retried, innerException);

src/Elasticsearch.Net/Exceptions/ElasticsearchServerException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Elasticsearch.Net
88
{
99
public class ElasticsearchServerException : Exception
1010
{
11-
private static readonly Regex ExceptionSplitter = new Regex(@"^([^\[]*?)\[(.*)\]", RegexOptions.Singleline);
11+
private static readonly Regex ExceptionSplitter = new Regex(@"^([^\[]+?)\[(.+)\]$", RegexOptions.Singleline);
1212
private static readonly string _couldNotParseServerException = "Could not parse server exception";
1313

1414
public int Status { get; set; }

src/Tests/Nest.Tests.Integration/IntegrationSetup.cs

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,56 @@ public static void Setup()
2222
var people = NestTestData.People;
2323
var boolTerms = NestTestData.BoolTerms;
2424

25-
var createIndexResult = client.CreateIndex(ElasticsearchConfiguration.DefaultIndex, c => c
26-
.NumberOfReplicas(0)
27-
.NumberOfShards(1)
28-
.AddMapping<ElasticsearchProject>(m => m
29-
.MapFromAttributes()
30-
.Properties(p => p
31-
.String(s => s.Name(ep => ep.Content).TermVector(TermVectorOption.WithPositionsOffsetsPayloads))))
32-
.AddMapping<Person>(m => m.MapFromAttributes())
33-
.AddMapping<BoolTerm>(m => m.Properties(pp=>pp
34-
.String(sm => sm.Name(p => p.Name1).Index(FieldIndexOption.NotAnalyzed))
35-
.String(sm => sm.Name(p => p.Name2).Index(FieldIndexOption.NotAnalyzed))
36-
))
37-
);
25+
try
26+
{
27+
var createIndexResult = client.CreateIndex(ElasticsearchConfiguration.DefaultIndex, c => c
28+
.NumberOfReplicas(0)
29+
.NumberOfShards(1)
30+
.AddMapping<ElasticsearchProject>(m => m
31+
.MapFromAttributes()
32+
.Properties(p => p
33+
.String(s => s.Name(ep => ep.Content).TermVector(TermVectorOption.WithPositionsOffsetsPayloads))))
34+
.AddMapping<Person>(m => m.MapFromAttributes())
35+
.AddMapping<BoolTerm>(m => m.Properties(pp => pp
36+
.String(sm => sm.Name(p => p.Name1).Index(FieldIndexOption.NotAnalyzed))
37+
.String(sm => sm.Name(p => p.Name2).Index(FieldIndexOption.NotAnalyzed))
38+
))
39+
);
3840

39-
var createAntotherIndexResult = client.CreateIndex(ElasticsearchConfiguration.DefaultIndex + "_clone", c => c
40-
.NumberOfReplicas(0)
41-
.NumberOfShards(1)
42-
.AddMapping<ElasticsearchProject>(m => m
43-
.MapFromAttributes()
44-
.Properties(p => p
45-
.String(s => s.Name(ep => ep.Content).TermVector(TermVectorOption.WithPositionsOffsetsPayloads))))
46-
.AddMapping<Person>(m => m.MapFromAttributes())
47-
.AddMapping<BoolTerm>(m => m.Properties(pp => pp
48-
.String(sm => sm.Name(p => p.Name1).Index(FieldIndexOption.NotAnalyzed))
49-
.String(sm => sm.Name(p => p.Name2).Index(FieldIndexOption.NotAnalyzed))
50-
))
51-
);
41+
var createAntotherIndexResult = client.CreateIndex(ElasticsearchConfiguration.DefaultIndex + "_clone", c => c
42+
.NumberOfReplicas(0)
43+
.NumberOfShards(1)
44+
.AddMapping<ElasticsearchProject>(m => m
45+
.MapFromAttributes()
46+
.Properties(p => p
47+
.String(s => s.Name(ep => ep.Content).TermVector(TermVectorOption.WithPositionsOffsetsPayloads))))
48+
.AddMapping<Person>(m => m.MapFromAttributes())
49+
.AddMapping<BoolTerm>(m => m.Properties(pp => pp
50+
.String(sm => sm.Name(p => p.Name1).Index(FieldIndexOption.NotAnalyzed))
51+
.String(sm => sm.Name(p => p.Name2).Index(FieldIndexOption.NotAnalyzed))
52+
))
53+
);
54+
55+
var bulkResponse = client.Bulk(b => b
56+
.IndexMany(projects)
57+
.IndexMany(people)
58+
.IndexMany(boolTerms)
59+
.Refresh()
60+
);
61+
}
62+
catch (Exception e)
63+
{
64+
65+
throw;
66+
}
5267

53-
var bulkResponse = client.Bulk(b=>b
54-
.IndexMany(projects)
55-
.IndexMany(people)
56-
.IndexMany(boolTerms)
57-
.Refresh()
58-
);
5968
}
6069

6170
[TearDown]
6271
public static void TearDown()
6372
{
64-
var client = ElasticsearchConfiguration.Client.Value;
65-
client.DeleteIndex(di => di.Indices(ElasticsearchConfiguration.DefaultIndex, ElasticsearchConfiguration.DefaultIndex + "_*"));
73+
var client = ElasticsearchConfiguration.Client.Value;
74+
client.DeleteIndex(di => di.Indices(ElasticsearchConfiguration.DefaultIndex, ElasticsearchConfiguration.DefaultIndexPrefix + "*"));
6675
}
6776
}
6877
}

0 commit comments

Comments
 (0)