title: HttpClient with infinite time out throws time out exception
body: <p>My HttpClient uses digest authentication to connect to the server and expects search queries in response. These search queries can come in any time so the client is expected to leave the connection open at all times.</p>
  
  <p>The connection is made using the following code:</p>
  
  <pre><code>public static async void ListenForSearchQueries(int resourceId)
  {
      var url = $"xxx/yyy/{resourceId}/waitForSearchRequest?token=abc";
  
      var httpHandler = new HttpClientHandler { PreAuthenticate = true };
  
      using (var digestAuthMessageHandler = new DigestAuthMessageHandler(httpHandler, "user", "password"))
      using (var client = new HttpClient(digestAuthMessageHandler))
      {
          client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite);
  
          var request = new HttpRequestMessage(HttpMethod.Get, url);
  
          var tokenSource = new CancellationTokenSource();
              tokenSource.CancelAfter(TimeSpan.FromMilliseconds(Timeout.Infinite));
  
          using (var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, tokenSource.Token))
          {
              Console.WriteLine("\nResponse code: " + response.StatusCode);
  
              using (var body = await response.Content.ReadAsStreamAsync())
              using (var reader = new StreamReader(body))
                  while (!reader.EndOfStream)
                      Console.WriteLine(reader.ReadLine());
           }
      }
  }
  </code></pre>
  
  <p>This is how the method is being used in the Main method of a console application.</p>
  
  <pre><code>private static void Main(string[] args)
  {
     const int serviceId = 128;
     .
     .
     .
     ListenForSearchQueries(resourceId);
     Console.ReadKey();
  }
  </code></pre>
  
  <p>This is what the output on the console window looks like:</p>
  
  <pre><code>Response code: OK
  --searchRequestBoundary
  </code></pre>
  
  <p>Even though the timeout for the client is set to infinity, the connection times out after roughly five minutes (which is not the default timeout of the HttpClient) after the first output, throwing the following exception.</p>
  
  <pre><code>System.IO.IOException occurred
    HResult=0x80131620
    Message=The read operation failed, see inner exception.
    Source=System.Net.Http
    StackTrace:
     at System.Net.Http.HttpClientHandler.WebExceptionWrapperStream.Read(Byte[] buffer, Int32 offset, Int32 count)
     at System.Net.Http.DelegatingStream.Read(Byte[] buffer, Int32 offset, Int32 count)
     at System.IO.StreamReader.ReadBuffer()
     at System.IO.StreamReader.get_EndOfStream()
     at ConsoleTester.Program.&lt;ListenSearchQueriesDigestAuthMessageHandler&gt;d__10.MoveNext() in C:\Users\xyz\ProjName\ConsoleTester\Program.cs:line 270
  
  Inner Exception 1:
  WebException: The operation has timed out.
  </code></pre>
  
  <p>The DelegateHandler used for the authentication is a a rough adaption of <a href="https://bitbucket.org/toburger/digestauthmessagehandler" rel="noreferrer">this</a> code (see the source section).</p>
  
  <p>Why is the client timing out and how can I prevent this?</p>
  
  <p>My ultimate goal is to make a call and wait indefinitely for a response. When a response does come, I don't want the connection to close because more responses might come in the future. Unfortunately, I can't change anything at the server end.</p>