Skip to content

Commit 370662a

Browse files
committed
Thrift connection timeout elastic#1159
Changed the Tsocket to timeout using the property from the connection-settings.
1 parent bfd2866 commit 370662a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public ThriftConnection(IConnectionConfigurationValues connectionSettings)
4343
{
4444
var host = uri.Host;
4545
var port = uri.Port;
46-
var tsocket = new TSocket(host, port);
46+
var tsocket = new TSocket(host, port, this._connectionSettings.Timeout);
4747
var transport = new TBufferedTransport(tsocket, 1024);
4848
var protocol = new TBinaryProtocol(transport);
4949
var client = new Rest.Client(protocol);

src/Connections/Elasticsearch.Net.Connection.Thrift/Transport/TSocket.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,16 @@ public override void Open()
117117
{
118118
InitSocket();
119119
}
120+
121+
var connectionRequest = client.BeginConnect(host, port, null, null);
122+
123+
var connected = connectionRequest.AsyncWaitHandle.WaitOne(timeout);
124+
125+
if (!connected)
126+
{
127+
throw new Exception("Failed to connect");
128+
}
120129

121-
client.Connect(host, port);
122130
inputStream = client.GetStream();
123131
outputStream = client.GetStream();
124132
}

0 commit comments

Comments
 (0)