locked
The underlying connection was closed: An unexpected error occurred on a send. RRS feed

  • Question

  • Early in January I developed a very simple Logic App which takes an HTTP trigger as an entry point. This Logic App simply takes a GET request, sends me an email, and then returns a 200 OK response to the client.

    I use it in conjunction with a VSTO add-in which calls the Logic App each time it is installed; so that I get a sense of growth. I did not receive any emails since early February, only then to recently discover this was because every time the VSTO add-in tries to call the trigger, it returns a "The underlying connection was closed: An unexpected error occurred on a send" exception:

    System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
       at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
       at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
       --- End of inner exception stack trace ---
       at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
       at System.Net.Connection.ReadCallback(IAsyncResult asyncResult)
       --- End of inner exception stack trace ---
       at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
       at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
       --- End of inner exception stack trace ---
       --- End of inner exception stack trace ---
       at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
       at ExcelAddIn...
     

    ---> (Inner Exception #0) System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
       at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
       at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
       --- End of inner exception stack trace ---
       at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
       at System.Net.Connection.ReadCallback(IAsyncResult asyncResult)
       --- End of inner exception stack trace ---
       at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
       at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
       --- End of inner exception stack trace ---<---

    The code within the VSTO addin has not changed since January, nor has the Logic App changed either. It was working fine for all clients, and is now not working for any of them. What I am even more surprised about, is that the Logic App log does not show any failed calls either.

    How can I debug this?


    • Edited by Ama_76 Thursday, March 5, 2020 9:45 PM more details on stack trace
    Thursday, March 5, 2020 9:40 PM

All replies

  • Hmm, is the issue consistent or intermittent? Per your log, if your Logic App has been triggering your workflow every time, and that there aren't any failed actions; specifically, if the Response connector that you're probably using to send 200 hasn't had any failures, it's most likely one of the downstream components at your VSTO infra side have had a change that is breaking the connection. Perhaps the service provider of the VSTO addin that you're using had a change in their backend? Isolating which component reproduces the issue consistently 100% would be a great starting point.

    The error itself is pretty generic and basically means the connection was closed unexpectedly so i would look into this SO post and see if any of the scenarios discussed match as well.
    Tuesday, March 10, 2020 6:41 AM
  • The connection was breaking because System.Net.Http.HttpClient would not use TLS1.2.

    I had to add the following line:

    ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol Or SecurityProtocolType.Tls12 And Not (SecurityProtocolType.Ssl3 Or SecurityProtocolType.Tls Or SecurityProtocolType.Tls11)

    Note

    ServicePointManager.SecurityProtocol =  SecurityProtocolType.Tls12

    would work, but I do not recommend hard coding a protocol so that the app will upgrade automatically when TLS1.3 comes out. But given the described experience, will it upgrade automatically?

    Could this be because Azure updated its policy re TLS1.1?


    • Edited by Ama_76 Monday, March 16, 2020 11:05 PM
    Monday, March 16, 2020 11:04 PM
  • Thanks for resolving this thread and sharing what worked to overcome the problem. I'm not aware of a policy update around TLS 1.1, could you elaborate?

    Tuesday, March 17, 2020 5:34 AM