Respawnsive / Apizr

Refit based web api client management, but resilient (retry, connectivity, cache, auth, log, priority, etc...)
https://www.apizr.net
Apache License 2.0
140 stars 12 forks source link

[External - Refit/Fusillade] Cannot access a disposed object. Object name: 'System.Net.Http.HttpConnection+HttpConnectionResponseContent'. #6

Closed dorisoy closed 2 years ago

dorisoy commented 3 years ago

Hi, @JeremyBP ,I use Apizr 1.9.0,I have an API request "GetPermissionRecordSettingAsync",when I try to send the same content twice (in case of timeout or similar), I get an "ObjectDisposedException" as follows:

[Get("/auth/user/permission/{userId}")] Task<APIResult<IList<PermissionRecordQuery>>> GetPermissionRecordSettingAsync([CacheKey] int store, int userId, CancellationToken calToken = default);

"exception": { "type": "Apizr.ApizrException1[[DCMS.Client.Services.APIResult1[[System.Collections.Generic.IList1[[DCMS.Client.Models.Users.PermissionRecordQuery, DCMS.Client, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], DCMS.Client, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null]]", "message": "Cannot access a disposed object.\nObject name: 'System.Net.Http.HttpConnection+HttpConnectionResponseContent'.", "stackTrace": " at Apizr.ApizrManager1[TWebApi].ExecuteAsync[TResult] (System.Linq.Expressions.Expression1[TDelegate] executeApiMethod, System.Threading.CancellationToken cancellationToken, Fusillade.Priority priority) [0x005e4] in :0 \n at DCMS.Client.Services.UserService.GetPermissionRecordSettingAsync (System.Action1[T] action, System.Threading.CancellationTokenSource cts) [0x0013c] in <c6379d2ab81547ef80e263b722f90018>:0 ", "innerExceptions": [ { "type": "System.ObjectDisposedException", "message": "Cannot access a disposed object.\nObject name: 'System.Net.Http.HttpConnection+HttpConnectionResponseContent'.", "stackTrace": " at System.Net.Http.HttpContent.CheckDisposed () [0x00013] in <92d3ef97a77047c9ab125ae979975a02>:0 \n at System.Net.Http.HttpContent.ReadAsStreamAsync () [0x00000] in <92d3ef97a77047c9ab125ae979975a02>:0 \n at Refit.NewtonsoftJsonContentSerializer.DeserializeAsync[T] (System.Net.Http.HttpContent content) [0x00027] in <ea3d892ff3f046868a691cc71dcbabbf>:0 \n at Refit.RequestBuilderImplementation.DeserializeContentAsync[T] (System.Net.Http.HttpResponseMessage resp, System.Net.Http.HttpContent content) [0x002d5] in <ea3d892ff3f046868a691cc71dcbabbf>:0 \n at Refit.RequestBuilderImplementation+<>c__DisplayClass14_02[T,TBody].b__0 (System.Net.Http.HttpClient client, System.Threading.CancellationToken ct, System.Object[] paramList) [0x003a5] in :0 \n at Apizr.ApizrManager1[TWebApi].ExecuteAsync[TResult] (System.Linq.Expressions.Expression1[TDelegate] executeApiMethod, System.Threading.CancellationToken cancellationToken, Fusillade.Priority priority) [0x00528] in :0 ", "wrapperSdkName": "appcenter.xamarin" } ], "wrapperSdkName": "appcenter.xamarin" }`

JeremyBP commented 3 years ago

Hi @dorisoy, yeah I noticed that and can repro this bug now. Will try to fix it this week. Thanks for reporting it.

JeremyBP commented 3 years ago

Could you please try to turn off Fusillade priority management feature (activated by default) from the WebApiAttribute or the fluent api? I wonder if it pass or fails on your side. It seems to be related to Refit while used with Fusillade. Actually I can reproduce the bug playing directly with Refit and Fusillade together (no Apizr at all) and I can find issues on GitHub talking about this bug #460 (closed but not fixed). I'm considering opening an issue on Refit repo and link it to this place.

On the other hand I'm currently working on Apizr v3.0-beta1 witch will outsource all Fusillade code from the core package to a dedicated integration one called Apizr.Integrations.Fusillade. As v3.0 will based on Refit v6 witch is currently in beta mode, I'll publish it into the pre-release channel. Also, Refit v6 introduce some breaking changes and Apizr v3 some to. I'll update the changelog when ready.

JeremyBP commented 3 years ago

Here is the issue opened on the Refit side #1048 and here on the Fusillade side #148

dorisoy commented 3 years ago

Could you please try to turn off Fusillade priority management feature (activated by default) from the WebApiAttribute or the fluent api? I wonder if it pass or fails on your side. It seems to be related to Refit while used with Fusillade. Actually I can reproduce the bug playing directly with Refit and Fusillade together (no Apizr at all) and I can find issues on GitHub talking about this bug #460 (closed but not fixed). I'm considering opening an issue on Refit repo and link it to this place.

On the other hand I'm currently working on Apizr v3.0-beta1 witch will outsource all Fusillade code from the core package to a dedicated integration one called Apizr.Integrations.Fusillade. As v3.0 will based on Refit v6 witch is currently in beta mode, I'll publish it into the pre-release channel. Also, Refit v6 introduce some breaking changes and Apizr v3 some to. I'll update the changelog when ready.

👍👍👍 Thank you for your timely reply, I will use your guidance!