title: Intermittent TFS agent error
body: <p>I am currently setting up TFS automatic builds and deployment at work and am getting a intermittent error.</p>
  
  <p>I am using Visual Studio Team Services (VSTS) with an on premises TFS agent. This works perfectly fine some of the time and then randomly the agent appears idle in VSTS, even though the agent job is still running. </p>
  
  <p>In the agent's log it has the following error:</p>
  
  <pre><code>[2016-10-24 23:50:42Z ERR  MessageListener] System.Net.Http.HttpRequestException: Error while copying content to a stream. ---&gt; System.IO.IOException: Unable to read data from the transport connection. The connection was closed before all data could be read. Expected 2251 bytes, read 0 bytes.
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Net.Http.StreamToStreamCopy.&lt;CopyAsyncToPreSizedLimitMemoryStream&gt;d__2.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Net.Http.HttpContent.&lt;LoadIntoBufferAsyncCore&gt;d__48.MoveNext()
     --- End of inner exception stack trace ---
     at System.Net.Http.HttpContent.&lt;LoadIntoBufferAsyncCore&gt;d__48.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Net.Http.HttpClient.&lt;FinishSendAsync&gt;d__58.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
     at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.&lt;SendAsync&gt;d__45.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
     at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.&lt;SendAsync&gt;d__42`1.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
     at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.&lt;SendAsync&gt;d__27`1.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
     at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.&lt;SendAsync&gt;d__26`1.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.VisualStudio.Services.Agent.Extensions.&lt;WithCancellation&gt;d__0`1.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  </code></pre>
  
  <p>Any ideas what could be causing this?</p>