refit icon indicating copy to clipboard operation
refit copied to clipboard

Ios async rest call never returns after upgrade to 4.0.0

Open michelmoorlag opened this issue 9 years ago • 15 comments

I love Refit and have been using it for my X.F. project. Recently I moved from PCL to .net standard for my shared code. I use Refit in combination with ModernHttpClient and up to version 3.1.0 all works fine. After upgrade to 4.0.0 or higher on Ios only my async rest calls seems to be awaiting for ever. I have added a working basic example project to demonstrate the issue, the rest call never returns. If you downgrade refit to 3.1.0 it will work. On android it is not a problem

My Interface:

    [Get("/posts/{postId}")]
    Task<PostModel> GetPostAsync(int postId);

My Code:

   var testApi  = RestService.For<ITestApi>(new HttpClient(new NativeMessageHandler()) { 
                          BaseAddress = new Uri("https://jsonplaceholder.typicode.com") });
            
   var post1 = await testApi.GetPostAsync(1);
   // With Refit 3.1.0 above line works fine
    // With Refit 4.0.0 and higher above line seems to await for ever

RefitTest.zip

michelmoorlag avatar Sep 07 '17 06:09 michelmoorlag

Deleted my previous comment as my libraries have indeed been updated to 4.0.1. I'm seeing the same issue and as above only on iOS, Android works fine.

fusionconsulting avatar Sep 07 '17 07:09 fusionconsulting

If you look with Fiddler, what do you see? Is the request actually being fired?

opcodewriter avatar Sep 09 '17 05:09 opcodewriter

Also, I wonder if this is related to another issue: https://github.com/paulcbetts/refit/issues/347

opcodewriter avatar Sep 09 '17 08:09 opcodewriter

Issue #347 is IOS only but that is the only resemblance.

  • In my case version 2.4.1 has no problem while the other do.
  • Also in the other issue an exception is thrown while in my case it does not.

So my feeling is that it is unrelated.

michelmoorlag avatar Sep 13 '17 13:09 michelmoorlag

If you look with Fiddler, what do you see? Is the request actually being fired?

I used nettop to monitor the network traffic that the ios simulator is generating and yes the request is being fired. With refit 3.x i see a connection with the backend "https://jsonplaceholder.typicode.com" = 104.31.86.157:443 is being made en data is returned.

refit3

With refit 4.x i see the same connection but the call never returns

refit4

michelmoorlag avatar Sep 13 '17 13:09 michelmoorlag

I just created a new sample app using Refit 4.0.1. Making a POST call to https://requestb.in which works as expected. The call returns just fine. Do you have a reproduction sample we can use?

Also this was without ModernHttpClient. Not going to add it since it is not maintained and broken on Android. You shouldn't use it...

Both HttpClientHandler and NSUrlSessionHandler work as expected.

Edit: Now also tried against typicode.com, this also works and returns as expected.

Cheesebaron avatar Sep 13 '17 14:09 Cheesebaron

Do you have a reproduction sample we can use?

Yes see the end of my first post: https://github.com/paulcbetts/refit/files/1283667/RefitTest.zip

One small update, change the line:

mainLabel.Text = post1.title

into

Device.BeginInvokeOnMainThread(() => mainLabel.Text = post1.title);

michelmoorlag avatar Sep 13 '17 14:09 michelmoorlag

The issue is with ModernHttpClient, not Refit.

Cheesebaron avatar Sep 13 '17 14:09 Cheesebaron

You are right, when I remove ModernHttpClient it does work indeed!

Also this was without ModernHttpClient. Not going to add it since it is not maintained and broken on Android. You shouldn't use it...

Do you have any reference of the above? I thought that ModernHttpClient was improving everything by using the native httpclient but it if you are right it makes things worse.

michelmoorlag avatar Sep 14 '17 06:09 michelmoorlag

Just go to the modernhttpclient repo, and see that it has been inactive for ages.

Xamarin provides its own native client handlers, which you should use instead.

Cheesebaron avatar Sep 14 '17 07:09 Cheesebaron

For now I removed ModernHttpClient and all works fine.

Xamarin provides its own native client handlers, which you should use instead.

Does this mean I can replace modernhttpclient with an other "native" httpclient to improve the performance? Do you have an example or where can I find the documentation?

Both HttpClientHandler and NSUrlSessionHandler work as expected.

Is this what you mean with "Xamarin provides its own native client handlers, which you should use instead." ? How should I use this? Can you share the example project you made to test this issue?

michelmoorlag avatar Sep 14 '17 11:09 michelmoorlag

I too have been using the ModernHttpClient based on a number of posts on the web. Can I respectively suggest that the repo and maybe nuget pages for ModernHttpClient be updated to reflect your advice that it isn't maintained and to avoid using it. Thanks.

daveclarke avatar Sep 21 '17 22:09 daveclarke

I don't have access to that repo, nor the nugets.

Cheesebaron avatar Sep 22 '17 09:09 Cheesebaron

This blog posts describe using Xamarin Native handlers: http://jonathanpeppers.com/Blog/improving-http-performance-in-xamarin-applications

torleifs avatar Jan 19 '18 09:01 torleifs

Closing as external

clairernovotny avatar Jan 28 '18 20:01 clairernovotny