diff --git a/src/Connections/Elasticsearch.Net.Connection.Thrift/ThriftConnection.cs b/src/Connections/Elasticsearch.Net.Connection.Thrift/ThriftConnection.cs index a037c0b537f..57e015c03b0 100644 --- a/src/Connections/Elasticsearch.Net.Connection.Thrift/ThriftConnection.cs +++ b/src/Connections/Elasticsearch.Net.Connection.Thrift/ThriftConnection.cs @@ -48,10 +48,11 @@ public ThriftConnection(IConnectionConfigurationValues connectionSettings, TProt var protocol = protocolFactory == null ? new TBinaryProtocol(transport) : protocolFactory.GetProtocol(transport); var client = new Rest.Client(protocol); + tsocket.ConnectTimeout = this._connectionSettings.PingTimeout.GetValueOrDefault(200); tsocket.Timeout = this._connectionSettings.Timeout; tsocket.TcpClient.SendTimeout = this._connectionSettings.Timeout; tsocket.TcpClient.ReceiveTimeout = this._connectionSettings.Timeout; - //tsocket.TcpClient.NoDelay = true; + tsocket.TcpClient.NoDelay = true; queue.Enqueue(client); diff --git a/src/Connections/Elasticsearch.Net.Connection.Thrift/Transport/TSocket.cs b/src/Connections/Elasticsearch.Net.Connection.Thrift/Transport/TSocket.cs index 0f74cb67434..8211b8ab98b 100644 --- a/src/Connections/Elasticsearch.Net.Connection.Thrift/Transport/TSocket.cs +++ b/src/Connections/Elasticsearch.Net.Connection.Thrift/Transport/TSocket.cs @@ -44,7 +44,8 @@ public TSocket(TcpClient client) } } - public TSocket(string host, int port) : this(host, port, 0) + public TSocket(string host, int port) + : this(host, port, 0) { } @@ -57,6 +58,8 @@ public TSocket(string host, int port, int timeout) InitSocket(); } + public int ConnectTimeout { get; set; } + public int Timeout { set { client.ReceiveTimeout = client.SendTimeout = timeout = value; } @@ -118,14 +121,14 @@ public override void Open() InitSocket(); } - - var connectionRequest = client.BeginConnect(host, port, null, null); - var connected = connectionRequest.AsyncWaitHandle.WaitOne(timeout); - if (!connected) - { - throw new TTransportException("Failed to connect"); - } + var connectionRequest = client.BeginConnect(host, port, null, null); + var connected = connectionRequest.AsyncWaitHandle.WaitOne(this.ConnectTimeout); + + if (!connected) + { + throw new TTransportException("Failed to connect"); + } inputStream = client.GetStream(); outputStream = client.GetStream();