An error occurred while communicating with the remote host. The error code is 0x80070032.

The logs of a web application running in IIS include an HttpException with an inner COMException and the message “An error occurred while communicating with the remote host. The error code is 0x80070032.” What’s going on and how can we fix it?

Before I go into the details, here’s some bad new: there could be many other causes of this error. You can see the symptoms of the error described in this article outlined below. Other symptoms may indicate a different cause for the same exceptions. For example, here, https://github.com/SignalR/SignalR/issues/1790 and https://stackoverflow.com/questions/5564862/the-remote-host-closed-the-connection-the-error-code-is-0x800704cd are other causes for this error.

Symptoms of error code 0x80070032

  • The error occurs after each app pool recycle or server restart.
  • Additionally and optionally: the error occurs periodically (e.g. each 21 minutes).
  • The error comes after a request from 127.0.0.1 (additional logging must be added to see this).
  • There are no corresponding IIS logs, i.e. there is no request logged at the time the error occurred.
  • The application log contains this exception:
An error occurred while communicating with the remote host. The error code is 0x80070032. System.Web.HttpException
    at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
    at System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()
    at System.Web.HttpResponse.Flush(Boolean finalFlush, Boolean async)
    at System.Web.HttpWriter.WriteFromStream(Byte[] data, Int32 offset, Int32 size)
    at System.IO.Stream.<>c.b__46_0(Object )
    at System.Threading.Tasks.Task`1.InnerInvoke()
    at System.Threading.Tasks.Task.Execute() --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.IO.Stream.EndWrite(IAsyncResult asyncResult)
    at Microsoft.Owin.Host.SystemWeb.CallStreams.OutputStream.EndWrite(IAsyncResult asyncResult)
    at System.Net.Http.StreamToStreamCopy.BufferWrittenCallback(IAsyncResult ar) --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Web.Http.Owin.HttpMessageHandlerAdapter.d__33.MoveNext() The request is not supported. (Exception from HRESULT: 0x80070032) System.Runtime.InteropServices.COMException 

In my case, the error code 0x80070032 occurred every 21 minutes…

The error occurred constantly every 21 minutes.
The error occurred consistently every 21 minutes.


…which incidentally correlated to the idle time-out configured in the web app’s application pool:

The app pool's idle time-out is set to 20 minutes.
The app pool’s idle time-out is set to 20 minutes.

So, what’s wrong?

Two things are happening here:

  • Periodic exceptions in application log: The app pool is configured to time-out after 20 minutes, but also to be always on (see the setting called Start Mode, it’s set to AlwaysRunning). This causes IIS to make a request to the app each time it times out.
  • Exceptions when recycling the app pool: The app pool’s Start Mode setting is set to AlwaysRunning which instructs IIS to make a request to the app as soon as it gets restarted.

In both cases IIS does not wait for any response from the app. Instead, the channel is closed and this is what causes the exception in the end.

And these are the possible fixes:

  • Periodic exceptions in application log: If the app is always supposed to be running, then set the Idle time-out to 0 to deactivate it. Otherwise, allow to app to sleep without being woken up by setting the Start Mode to OnDemand.
  • Exceptions when recycling the app pool: If it’s ok for the first user request to take a bit longer to wake up the app, just set the Start Mode setting to OnDemand. It’s a bit more complicated than that if the auto-start behavior is required. In this case, you must edit the application logger to actively ignore that error.

Freelance full-stack .NET and JS developer and architect. Located near Cologne, Germany.

Leave a Reply

Your email address will not be published. Required fields are marked *