问题
I am getting reports from amazon reports API using ASP.NET MVC 4.7. I have tested the web app on my local computer and everything works fine. Unfortunately, this is not the case when I publish the site to my HostGator shared server. I continue to get the following error:
The underlying connection was closed: An unexpected error occurred on a send.
System.IO.IOException: Authentication failed because the remote party has closed the transport stream
I have found that as soon as I publish the site everything works perfect. After a couple minutes of idling (about 5 minutes) I start to get the error.
What I have tried:
Turn off firewalls.
Contacted HostGator and ensured they are not blocking any IPs
I tried adding the following to my startup class as well as right before the request:
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;`
Added
ServicePointManager.Expect100Continue = false;
to my startup class. Before adding this I had the error 100% of the time. Now it is working but for a couple min.I have read a dozen stackoverflow questions that have the same error. Most of them recommend adding all the certs as I did above none of which have worked.
I don't know if it is related but when I run this on my host server and look at the log for the connection error. At one point it references my local host "C:\Users\John\Programs\WebApp-ASPNET\V1.3977p\webapp\Amz_MWS\Web\MarketplaceWebService\MarketplaceWebServiceClient.cs" See below. Why would it reference my local host address????
2019-09-02 19:43:13,652 FATAL[MarketplaceWebService.MarketplaceWebServiceClient]: InnerWebException : System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Authentication failed because the remote party has closed the transport stream.
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.TlsStream.CallProcessAuthentication(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.ConnectStream.WriteHeaders(Boolean async)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at MarketplaceWebService.MarketplaceWebServiceClient.Invoke[T,K](IDictionary 2 parameters, K clazz) in C:\Users\John\Programs\WebApp-ASPNET\V1.3977p\webapp\Amz_MWS\Web\MarketplaceWebService\MarketplaceWebServiceClient.cs:line 599
2019-09-02 19:43:13,652 ERROR[MarketplaceWebService.Samples.GetReportRequestListSample]: Caught Exception: The underlying connection was closed: An unexpected error occurred on a send.
Thank you for any help in advance.
来源:https://stackoverflow.com/questions/57837975/intermittent-connection-error-on-api-call-until-manual-recycle-of-iis-app-pool