Skip to content

Commit 3e1fc81

Browse files
committed
found another exception irregularity synchronous calls with a connection pool with only ONE node did not throw maxretry but let the original exception bubble.
1 parent a92aac3 commit 3e1fc81

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

src/Elasticsearch.Net/Connection/Transport.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class Transport : ITransport
3232
private readonly IConnectionPool _connectionPool;
3333
private readonly IDateTimeProvider _dateTimeProvider;
3434
private DateTime? _lastSniff;
35+
private bool _throwMaxRetry;
3536

3637
public IConnectionConfigurationValues Settings { get { return ConfigurationValues; } }
3738
public IElasticsearchSerializer Serializer { get { return _serializer; } }
@@ -47,6 +48,7 @@ public Transport(
4748
this.Connection = connection ?? new HttpConnection(configurationValues);
4849
this._serializer = serializer ?? new ElasticsearchDefaultSerializer();
4950
this._connectionPool = this.ConfigurationValues.ConnectionPool;
51+
this._throwMaxRetry = !(this._connectionPool is SingleNodeConnectionPool);
5052

5153
this._dateTimeProvider = dateTimeProvider ?? new DateTimeProvider();
5254

@@ -362,7 +364,11 @@ private ElasticsearchResponse<T> DoRequest<T>(TransportRequestState<T> requestSt
362364
{
363365
requestState.SeenExceptions.Add(e);
364366
if (maxRetries == 0 && retried == 0)
365-
throw;
367+
{
368+
if (_throwMaxRetry)
369+
new MaxRetryException(e);
370+
else throw;
371+
}
366372
seenError = true;
367373
return RetryRequest<T>(requestState);
368374
}

src/Tests/Nest.Tests.Integration/Exceptions/ElasticsearchExceptionTests.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,44 @@ public void WebException_WithThrowingClient_ThrowsMappedException()
105105
var e = Assert.Throws<ElasticsearchServerException>(() => client.Search<ElasticsearchProject>(s => s.QueryRaw(@"{ ""badjson"" : {} }")));
106106
e.ExceptionType.Should().Contain("SearchPhaseExecutionException");
107107
}
108-
109-
108+
109+
[Test]
110+
public void ConnectionPool_SingleNode_PingExceptionThrowsMaxRetry()
111+
{
112+
var uris = new []
113+
{
114+
ElasticsearchConfiguration.CreateBaseUri(9201),
115+
};
116+
var connectionPool = new StaticConnectionPool(uris);
117+
var client = new ElasticClient(new ConnectionSettings(connectionPool)
118+
.SetTimeout(1000)
119+
);
120+
var e = Assert.Throws<MaxRetryException>(() =>
121+
{
122+
var result = client.Search<ElasticsearchProject>(s => s.MatchAll());
123+
result.IsValid.Should().BeFalse();
124+
});
125+
e.Should().NotBeNull();
126+
}
127+
128+
[Test]
129+
public void ConnectionPool_SingleNode_PingExceptionThrowsMaxRetry_Async()
130+
{
131+
var uris = new []
132+
{
133+
ElasticsearchConfiguration.CreateBaseUri(9201),
134+
};
135+
var connectionPool = new StaticConnectionPool(uris);
136+
var client = new ElasticClient(new ConnectionSettings(connectionPool)
137+
.SetTimeout(1000)
138+
);
139+
var e = Assert.Throws<MaxRetryException>(async () =>
140+
{
141+
var result = await client.SearchAsync<ElasticsearchProject>(s => s.MatchAll());
142+
result.IsValid.Should().BeFalse();
143+
});
144+
e.Should().NotBeNull();
145+
}
110146
[Test]
111147
public void ConnectionPool_DoesNotThrowOnServerExceptions_ThrowsMaxRetryException_OnDeadNodes()
112148
{

0 commit comments

Comments
 (0)