Skip to content

Thrift connection timeout on TcpClient.Connect() #1159

@eddyzanda

Description

@eddyzanda

Hi @Mpdreamz,

We have an app that uses the thriftconnection to talk with elastic-server (es-sever).

We noticed that if es-server is unreachable the client takes long to timeout.

After some checks we changed the Thrift.Transport-socket-sconnect to "honor" the timeout property in the connection settings.

ConnectionSettings.SetTimeout(1000)

Modified the client connect code from:

namespace Elasticsearch.Net.Connection.Thrift.Transport
public class TSocket 
{
 public override void Open()
 {
  ...
  client.Connect(host, port);
 }

to:

public override void Open()
{
 ...
 var result = client.BeginConnect(host, port, null, null);    
 var sucess = result.AsyncWaitHandle.WaitOne(timeout);
 if (!sucess)
 {
  throw new Exception("Failed to connect");
 }
}

What are your thought on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions