Skip to content

Commit d5a743d

Browse files
committed
Merge pull request #565 from danp60/bugfix/close_bad_thrift_connections
Thrift connection pool does not clean up stale connections
2 parents 9486a09 + d1edd00 commit d5a743d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Configuration;
5-
using System.IO;
5+
using System.IO;
6+
using System.Net.Sockets;
67
using System.Security.Cryptography.X509Certificates;
78
using System.Text;
89
using System.Threading;
@@ -284,6 +285,16 @@ private ElasticsearchResponse<Stream> Execute(RestRequest restRequest, object de
284285
return response;
285286
}
286287
}
288+
catch (SocketException)
289+
{
290+
client.InputProtocol.Transport.Close();
291+
throw;
292+
}
293+
catch (IOException)
294+
{
295+
client.InputProtocol.Transport.Close();
296+
throw;
297+
}
287298
finally
288299
{
289300
//make sure we make the client available again.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public override void Close()
7878
{
7979
outputBuffer.Close();
8080
}
81+
if (transport != null)
82+
{
83+
transport.Close();
84+
}
8185
}
8286

8387
public override int Read(byte[] buf, int off, int len)

0 commit comments

Comments
 (0)