title: HTTP requests stops working after some time
body: <p>I have strange problem with my Game written in Unity (Mono). I have login functionality and then, after successfull login i'm sending some kind of keep-alive requests to ensure token is updated (I'm sending it every 30s).</p>
  
  <p>The problem is, that after some time (sometimes it's 1 hour, sometimes 2.5 hours) all my requests have timeout status.</p>
  
  <p>To be sure about my connection status I made some checks in code: I'm making simple GET to <a href="http://google.com" rel="nofollow noreferrer">http://google.com</a> and to main website of my API (not an API call. Just website GET). When I got timeout on API next time i figured out that:</p>
  
  <ul>
  <li>After 1 timeout I have it always. Restarting application helps</li>
  <li>I'm getting timeouts on API call and on GET request for base API website</li>
  <li>Google is still responding with status 200 (no timeouts here)</li>
  </ul>
  
  <p>Implementation:
  On beginning i've been using <code>RestSharp</code> to handle requests, but the problem occured and there was a decision to throw <code>RestSharp</code> away and now we're using classic <code>WebClient</code></p>
  
  <pre><code>class BetterWebClient : WebClient
  {
      private WebRequest _Request = null;
      public TimeSpan? Timeout { get; set; }
      protected override WebRequest GetWebRequest(Uri address)
      {
          this._Request = base.GetWebRequest(address);
          if ( Timeout.HasValue )
          {
              _Request.Timeout = (int)Timeout.Value.TotalMilliseconds;
          }
          else
          {
              _Request.Timeout = 10*1000; //10s
          }
          if (this._Request is HttpWebRequest)
          {
              ((HttpWebRequest)this._Request).AllowAutoRedirect = true;
          }
  
          return this._Request;
      }
  }
  </code></pre>
  
  <p>My HandleRequest function (which also calls Google and API website) looks like this:</p>
  
  <pre><code>public static void HandleRequest&lt;TR&gt;(string url, RestResponse&lt;TR&gt; executeGetRequest) where TR : new()
  {
      using (BetterWebClient w = new BetterWebClient() {Timeout = TimeSpan.FromSeconds(2)})
      {
          try
          {
              string downloadString = w.DownloadString("http://www.google.com");
              Debug.Log("Google request: OK");
          }
          catch ( Exception )
          {
              Debug.LogError("Google request failed");
          }
  
          try
          {
              string downloadString = w.DownloadString("myAPIwebsite");
              Debug.Log("WorldOfRescue.com request: OK");
          }
          catch ( Exception )
          {
              Debug.LogError("WorldOfRescue.com request failed");
          }
      }
      var client = new BetterWebClient() {Timeout = TimeSpan.FromSeconds(5)};
      client.Headers.Add("Accept", "application/json");
      client.Headers.Add("Content-Type", "application/json");
      try
      {
          string downloadString = client.DownloadString(url);
  
          Debug.Log("Request for "+url+ " completed. Response: " + downloadString);
      }
      catch ( WebException e )
      {
          Debug.Log(e.Status);
  
          throw;
      }
      catch ( Exception e )
      {
          Debug.Log(e.ToString());
          throw;
      }
      finally
      {
          client.Dispose();
      }
  }
  </code></pre>
  
  <p>Do you have any idea why it happens? It looks like something is blocking me to send request to specific website, but in same time other website is working fine.</p>