title: C# HttpClient TaskCanceledException and SocketException
body: <p>We have an old system with a lot of code similar below:</p>
  <pre><code>using(var httpClient = new HttpClient()){...}
  </code></pre>
  <p>We aren't able to update the code at the moment because that will require some approval from our boss and our client.</p>
  <p>Recently we added some feature and we are using Unity for DI and we added the HttpClient as singleton in our DI Container</p>
  <pre><code>container.RegisterSingleton&lt;HttpClient&gt;();
  </code></pre>
  <p>and we are injecting the instance in our service.
  But after we deploy the changes we are getting below errors:</p>
  <ol>
  <li>One or more errors occurred. A task was canceled.</li>
  <li>SocketException with the message of A connection that was expected to be kept alive was closed by the server. ....</li>
  </ol>
  <p>After reading some questions online, I found this <a href="https://stackoverflow.com/questions/29179848/httpclient-a-task-was-cancelled">HttpClient - A task was cancelled?</a></p>
  <blockquote>
  <p>Disposing the HttpClient instance can cause following HTTP requests started by other instances of HttpClient to be cancelled!</p>
  </blockquote>
  <p>Does it mean, the <code>using() statements</code> was disposing the instance in DI container?</p>