I have been troubleshooting this issue for many hours now and wonder if someone else has come across the same issue?
I have a ServiceStack server running on .NET Core 2.1 within IIS using ServiceStack 5.5.1. I then have a WPF client also running ServiceStack 5.5.1 on .NET Framework 4.8.
The WPF creates an instance of a class which contacts a single instance of JsonServiceClient within the class.The JsonServiceClient is then used in various methods within the class. The JsonServiceClient is called with async / await.
Everything seems to work fine and then all of a sudden I will get a timeout e.g.
ServiceStack.AsyncServiceClient [(null)] - Exception Reading Response Error: The request timed out
System.Net.WebException: The request timed out ---> System.Net.WebException: The request was aborted: The request was canceled.
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- 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.TaskAwaiter.ValidateEnd(Task task)
at ServiceStack.AsyncServiceClient.<SendWebRequestAsync>d__146`1.MoveNext() in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Client\AsyncServiceClient.cs:line 259
--- End of inner exception stack trace ---
From looking at the server logs it doesn’t appear to have reached it. But if I leave it a minute and try again it will be fine without restarting the client or server.
It is almost like there is a limit to the amount of requests that can be made as sometimes two or three jsonClient Get methods may be called at once. That steered me towards the ServicePointManager.DefaultConnectionLimit. I set this to 100 as a test in the server Startup.cs but it doesn’t make a difference.
Has anyone else experienced this? My IIS is running on Windows Server 2016, is there any special configuration required in IIS?
.NET’s HttpWebRequest is a .NET Framework library so the same implementation gets run on all .NET Frameworks.
I can’t tell you why it’s happening, only where it’s happening and what the Exception is, i.e. basically repeating the contents of the Exception StackTrace.
One thing with Async is that it’s Task API was retrofitted on top of .NET’s HttpWebRequest APM model whereas .NET’s new HttpClient was designed around C# async/await so it’s possible using JsonHttpClient from ServiceStack.HttpClient NuGet package would be more reliable, or at least provide better diagnostics in async Exceptions.
I switched to JsonHttpClient and so far so good, thank you!
Is there a similar alternative to ServerEventsClient? Originally I was using my ServerEventsClient connection to do all my client requests and I was getting the same timeout error after a few requests. This is why I started using a second connection JsonServiceClient but experienced the same issue which lead me to my post.
All .NET HttpWebRequest implementations are limited by the same ServicePointManager restrictions, using different instances doesn’t avoid the restrictions.
If you’re still having issues you may want to look at limiting the amount of concurrent connections you’re making, e.g. making an async request for each item in a collection as in your example sends multiple I/O requests. It’s fairly inefficient to send multiple I/O requests from an unbounded collection like this. You can reduce the number of connections by batching requests, either by creating a Service that accepts multiple Customer Ids or sending an Auto Batched Request.