Skip to content

Commit 251d92e

Browse files
committed
Merge pull request #1205 from elasticsearch/fix/thrift-connect-timeout
Use ConnectTimeout instead of PingTimeout for thrift connections
2 parents 7b58f10 + 4958636 commit 251d92e

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

src/Connections/Elasticsearch.Net.Connection.Thrift/ThriftConnection.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ private Rest.Client CreateClient(Uri uri, ConcurrentQueue<Rest.Client> queue)
246246
var protocol = _protocolFactory == null ? new TBinaryProtocol(transport) : _protocolFactory.GetProtocol(transport);
247247

248248
var client = new Rest.Client(protocol);
249-
tsocket.ConnectTimeout = this._connectionSettings.PingTimeout.GetValueOrDefault(200);
249+
tsocket.ConnectTimeout = this._connectionSettings.ConnectTimeout.GetValueOrDefault(200);
250250
tsocket.Timeout = this._connectionSettings.Timeout;
251251
tsocket.TcpClient.SendTimeout = this._connectionSettings.Timeout;
252252
tsocket.TcpClient.ReceiveTimeout = this._connectionSettings.Timeout;

src/Elasticsearch.Net/Connection/Configuration/ConnectionConfiguration.cs

+18-5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ public class ConnectionConfiguration<T> : IConnectionConfigurationValues, IHideO
5353
int IConnectionConfigurationValues.Timeout { get { return _timeout; }}
5454

5555
private int? _pingTimeout;
56-
int? IConnectionConfigurationValues.PingTimeout { get{ return _pingTimeout; } }
56+
int? IConnectionConfigurationValues.PingTimeout { get { return _pingTimeout; } }
57+
58+
private int? _connectTimeout;
59+
int? IConnectionConfigurationValues.ConnectTimeout { get { return _connectTimeout; } }
5760

5861
private int? _deadTimeout;
5962
int? IConnectionConfigurationValues.DeadTimeout { get{ return _deadTimeout; } }
@@ -240,8 +243,8 @@ public T SetGlobalQueryStringParameters(NameValueCollection queryStringParameter
240243
}
241244

242245
/// <summary>
243-
/// Timeout in milliseconds when the .NET webrequest should abort the request, note that you can set this to a high value here,
244-
/// and specify the timeout in various calls on Elasticsearch's side.
246+
/// Sets the default timeout in milliseconds for each request to Elasticsearch.
247+
/// NOTE: You can set this to a high value here, and specify the timeout on Elasticsearch's side.
245248
/// </summary>
246249
/// <param name="timeout">time out in milliseconds</param>
247250
public T SetTimeout(int timeout)
@@ -251,15 +254,25 @@ public T SetTimeout(int timeout)
251254
}
252255

253256
/// <summary>
254-
/// This is a separate timeout for Ping() requests. A ping should fail as fast as possible.
257+
/// Sets the default ping timeout in milliseconds for ping requests, which are used
258+
/// to determine whether a node is alive. Pings should fail as fast as possible.
255259
/// </summary>
256-
/// <param name="timeout">The ping timeout in milliseconds defaults to 200</param>
260+
/// <param name="timeout">The ping timeout in milliseconds defaults to 1000, or 2000 is using SSL.</param>
257261
public T SetPingTimeout(int timeout)
258262
{
259263
this._pingTimeout = timeout;
260264
return (T) this;
261265
}
262266

267+
/// <summary>
268+
/// Sets the default connection timeout in milliseconds.
269+
/// </summary>
270+
public T SetConnectTimeout(int timeout)
271+
{
272+
this._connectTimeout = timeout;
273+
return (T)this;
274+
}
275+
263276
/// <summary>
264277
/// Sets the default dead timeout factor when a node has been marked dead.
265278
/// </summary>

src/Elasticsearch.Net/Connection/Configuration/IConnectionConfigurationValues.cs

+14-9
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,19 @@ public interface IConnectionConfigurationValues
2323
int MaximumAsyncConnections { get; }
2424

2525
/// <summary>
26-
/// The time out for calls to elasticsearch
26+
/// The timeout in milliseconds for each request to Elasticsearch
2727
/// </summary>
2828
int Timeout { get; }
2929

3030
/// <summary>
31-
/// The timeout in milliseconds to use for ping calls that are issues to check whether a node is up or not.
31+
/// The timeout in milliseconds to use for ping requests, which are issued to determine whether a node is alive
3232
/// </summary>
3333
int? PingTimeout { get; }
34+
35+
/// <summary>
36+
/// The connect timeout in milliseconds
37+
/// </summary>
38+
int? ConnectTimeout { get; }
3439

3540
/// <summary>
3641
/// The time to put dead nodes out of rotation (this will be multiplied by the number of times they've been dead)
@@ -41,21 +46,21 @@ public interface IConnectionConfigurationValues
4146
/// The maximum ammount of time a node is allowed to marked dead
4247
/// </summary>
4348
int? MaxDeadTimeout { get; }
44-
45-
/// <summary>
46-
/// When a retryable exception occurs or status code is returned this controls the maximum
47-
/// amount of times we should retry the call to elasticsearch
48-
/// </summary>
49-
int? MaxRetries { get; }
5049

5150
/// <summary>
5251
/// Limits the total runtime including retries separately from <see cref="Timeout"/>
5352
/// <pre>
54-
/// When not specified defaults to <see cref="Timeout"/> which itself defaults to 60seconds
53+
/// When not specified defaults to <see cref="Timeout"/> which itself defaults to 60 seconds
5554
/// </pre>
5655
/// </summary>
5756
TimeSpan? MaxRetryTimeout { get; }
5857

58+
/// <summary>
59+
/// When a retryable exception occurs or status code is returned this controls the maximum
60+
/// amount of times we should retry the call to elasticsearch
61+
/// </summary>
62+
int? MaxRetries { get; }
63+
5964
/// <summary>
6065
/// This signals that we do not want to send initial pings to unknown/previously dead nodes
6166
/// and just send the call straightaway

0 commit comments

Comments
 (0)