FubarDevelopment / restsharp.portable

Some kind of a RestSharp port to PCL
BSD 2-Clause "Simplified" License
96 stars 33 forks source link

RestClient.Execute hangs sometimes #82

Closed Ed156 closed 8 years ago

Ed156 commented 8 years ago

Hi there,

I have implemented RestSharp.Portable v3.3 in a WinForms MDI application, using async a lot.

It works, but when stress testing the application (starting multiple windows simultanously) I notice that regularly the below method stays in the restClient.Execute line. I also tried to add a CancellationTokenSource to set a timeout but I see no difference, it does not timeout. On the cases it hangs, the lines after the Execute call are not reached anymore during the rest of the time the application runs.

Anyone have any idea what could be the problem?

        public async Task<List<T>> ExecRestList<T>(RestRequest request, object obj)
        {
            var list = new List<T>();
            try
            {
                dialogService.ProcessStarted();

                if (obj != null)
                    request.AddBody(obj);

                using (var restClient = new RestClient(settings.Url))
                {
                    var response = await restClient.Execute<List<T>>(request);

                    if (response.IsSuccess)
                        list.AddRange(response.Data);
                }
            }
            catch (Exception ex)
            {
                HandleWebException(ex, request);

                if (list == null)
                    list = new List<T>();
            }
            finally
            {
                dialogService.ProcessCompleted();
            }

            return list;
        }
fubar-coder commented 8 years ago

That is strange. I'll take a look at this problem.

Ed156 commented 8 years ago

Great, let me know if you need more info.

evnik commented 8 years ago

@Ed156, have you tried to disable the context capture? var response = await restClient.Execute<List<T>>(request).ConfigureAwait(false);

Ed156 commented 8 years ago

Thanks evnik, I just tried that but it did not seem to make a difference. I will do more testing though.

Ed156 commented 8 years ago

I have been testing more, and the problem persists. Disabling the context capture does not make a difference. I am testing forms with a request that returns 700 Kb of data. I start the form about 5 times simultanously. Some forms get the data, but most not. When not, the code after the await restClient.Execute is never reached.

Fiddler does show ALL the requests however, with the correct size and 200 resultcode!

Ed156 commented 8 years ago

Another strange thing is that, when loading my app, a call to the same method creates problems because after the call to restClient.Execute, the current thread is changed from Main thread to Worker thread. This creates errors of course when I do ui stuff afterwards. The result value is ok though.

Could this be related?

Are there known issues with using this lib from Winforms?

Ed156 commented 8 years ago

I changed my code to use HttpClient and Json.net directly. Problem solved.