You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2014/07/25 22:04:12 UTC
git commit: THRIFT-1260 The thrift THttpclient in c# client is not
closing the connections when calling SendRequest Client: C# Patch: Rush
Manbert
Repository: thrift
Updated Branches:
refs/heads/master fb6ed7ead -> 7dce7b2a3
THRIFT-1260 The thrift THttpclient in c# client is not closing the connections when calling SendRequest
Client: C#
Patch: Rush Manbert
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/7dce7b2a
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/7dce7b2a
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/7dce7b2a
Branch: refs/heads/master
Commit: 7dce7b2a306900bbf181fab70a86fac71b67eae8
Parents: fb6ed7e
Author: Jens Geyer <je...@apache.org>
Authored: Fri Jul 25 22:00:44 2014 +0200
Committer: Jens Geyer <je...@apache.org>
Committed: Fri Jul 25 22:00:44 2014 +0200
----------------------------------------------------------------------
lib/csharp/src/Transport/THttpClient.cs | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/7dce7b2a/lib/csharp/src/Transport/THttpClient.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/THttpClient.cs b/lib/csharp/src/Transport/THttpClient.cs
index 2acf468..1581e83 100644
--- a/lib/csharp/src/Transport/THttpClient.cs
+++ b/lib/csharp/src/Transport/THttpClient.cs
@@ -173,7 +173,26 @@ namespace Thrift.Transport
using (Stream requestStream = connection.GetRequestStream())
{
requestStream.Write(data, 0, data.Length);
- inputStream = connection.GetResponse().GetResponseStream();
+
+ // Resolve HTTP hang that can happens after successive calls by making sure
+ // that we release the response and response stream. To support this, we copy
+ // the response to a memory stream.
+ using (var response = connection.GetResponse())
+ {
+ using (var responseStream = response.GetResponseStream())
+ {
+ // Copy the response to a memory stream so that we can
+ // cleanly close the response and response stream.
+ inputStream = new MemoryStream();
+ byte[] buffer = new byte[8096];
+ int bytesRead;
+ while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0)
+ {
+ inputStream.Write (buffer, 0, bytesRead);
+ }
+ inputStream.Seek(0, 0);
+ }
+ }
}
}
catch (IOException iox)