I have an app that uses Restsharp to get data from third parties.
After a few days running, doing roughly 250 queries per hour, all queries will fail with this:
The request was aborted: The connection was closed unexpectedly.
Doing the same query with curl works properly and is happening with a variety of endpoints.
Restarting the app cures the problem, until next time.
This is the code:
var Client = new RestClient("http://...");
var Request = new RestRequest("...", Method.GET);
Request.AddHeader("X-auth-Token", KEY);
Request.AddQueryParameter("timeFrame", TimeFrame);
// execute the query
var Response = Client.Execute(Request);
if (Response.StatusCode != HttpStatusCode.OK)
{
Logging.Error($"{FeedId()} - Failed to get {Response.ResponseUri}, error is {Response.StatusCode} : {Response.ErrorMessage}");
return false;
}
This method is called from multiple threads.
HttpWebResponse.Close
, it says "allow to reuse connection", which means that the connection is being kept open. I am planning to move RestSharp to use HttpClient, reusing a pool of clients. – Alexey Zimarev Dec 14 '17 at 8:00