diff --git a/src/Connections/Elasticsearch.Net.Connection.Thrift/ThriftConnection.cs b/src/Connections/Elasticsearch.Net.Connection.Thrift/ThriftConnection.cs index 00ba240172e..3d6b51292cf 100644 --- a/src/Connections/Elasticsearch.Net.Connection.Thrift/ThriftConnection.cs +++ b/src/Connections/Elasticsearch.Net.Connection.Thrift/ThriftConnection.cs @@ -2,7 +2,8 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Configuration; -using System.IO; +using System.IO; +using System.Net.Sockets; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading; @@ -284,6 +285,16 @@ private ElasticsearchResponse Execute(RestRequest restRequest, object de return response; } } + catch (SocketException) + { + client.InputProtocol.Transport.Close(); + throw; + } + catch (IOException) + { + client.InputProtocol.Transport.Close(); + throw; + } finally { //make sure we make the client available again. diff --git a/src/Connections/Elasticsearch.Net.Connection.Thrift/Transport/TBufferedTransport.cs b/src/Connections/Elasticsearch.Net.Connection.Thrift/Transport/TBufferedTransport.cs index 54df9969f96..6b21f8fe0cf 100644 --- a/src/Connections/Elasticsearch.Net.Connection.Thrift/Transport/TBufferedTransport.cs +++ b/src/Connections/Elasticsearch.Net.Connection.Thrift/Transport/TBufferedTransport.cs @@ -78,6 +78,10 @@ public override void Close() { outputBuffer.Close(); } + if (transport != null) + { + transport.Close(); + } } public override int Read(byte[] buf, int off, int len)