FFImageLoading
FFImageLoading copied to clipboard
ObjectExtensions.TryDispose (System.IDisposable obj) exception
🐛 Bug Report
ObjectExtensions.TryDispose (System.IDisposable obj) Java.Lang.IllegalStateException: Unbalanced enter/exit
Expected behavior
JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) InputStream.Close () InputStreamInvoker.Close () Stream.Dispose () (wrapper remoting-invoke-with-check) System.IO.Stream.Dispose() BufferedStream.Dispose (System.Boolean disposing) Stream.Close () Stream.Dispose () (wrapper remoting-invoke-with-check) System.IO.Stream.Dispose() DelegatingStream.Dispose (System.Boolean disposing) Stream.Close () Stream.Dispose () ObjectExtensions.TryDispose (System.IDisposable obj) DownloadCache+<>c__DisplayClass16_1.<DownloadAsync>b__1 () <.cctor>b__26_0 (System.Object obj) CancellationCallbackInfo.ExecutionContextCallback (System.Object obj) ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) CancellationCallbackInfo.ExecuteCallback () CancellationTokenSource.CancellationCallbackCoreWork (System.Threading.CancellationCallbackCoreWorkArguments args) CancellationTokenSource.ExecuteCallbackHandlers (System.Boolean throwOnFirstException) java.lang.IllegalStateException: Unbalanced enter/exit com.android.okhttp.okio.AsyncTimeout.enter AsyncTimeout.java:64 com.android.okhttp.okio.AsyncTimeout$2.read AsyncTimeout.java:211 com.android.okhttp.okio.RealBufferedSource.read RealBufferedSource.java:51 com.android.okhttp.internal.http.Http1xStream$FixedLengthSource.read Http1xStream.java:395 com.android.okhttp.internal.Util.skipAll Util.java:165 com.android.okhttp.internal.Util.discard Util.java:147 com.android.okhttp.internal.http.Http1xStream$FixedLengthSource.close Http1xStream.java:412 com.android.okhttp.okio.RealBufferedSource.close RealBufferedSource.java:397 com.android.okhttp.okio.RealBufferedSource$1.close RealBufferedSource.java:385
Configuration
Version: 2.4.11.982
Platform:
- Android
@paleicikas
I' am also getting this error! I also use version 2.4.11.982
I get it in my company's WiFi only. In my house and through mobile(3G/4G) there is no issue. If this info can be helpful in any way.
It seems that problem there - captured variable is disposed in the outer scope:
https://github.com/luberda-molinet/FFImageLoading/blob/5d83a4bfec44a643c24205fd3ae7f737c3c8bf10/source/FFImageLoading.Common/Cache/DownloadCache.cs#L157
This is crashing my app unfortunately
So, I tried 2 previous nuget versions of the package but still getting this error. Based on @paleicikas comment above, I searched for the configuration options if there is a way to disable DownLaodCache (I assume this is Memory Cache) and use only the disk cache - no luck. The configuration options are stated here: https://github.com/luberda-molinet/FFImageLoading/blob/master/source/FFImageLoading.Common/Config/Configuration.cs
Any suggestion to overcome this in any way, is more than welcome.
This propject is crucial for my company and I am under pressure to come up with a solution. There is no time for package change or expirimentation. So as a workaround I set up a custom HTTP client for FFImageLoading to use, and set the connection timeout to 5 minutes. Seems to "hide" the issue for the time being. I post here the configuration change just in case someone comes to need:
var config = new FFImageLoading.Config.Configuration()
{
HttpHeadersTimeout = 300,
HttpReadTimeout = 300,
DiskCacheDuration = TimeSpan.FromDays(360d),
TryToReadDiskCacheDurationFromHttpHeaders = false,
ExecuteCallbacksOnUIThread = true,
HttpClient = new HttpClient(new AndroidClientHandler()
{
ConnectTimeout = TimeSpan.FromMinutes(5),
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
}),
};
ImageService.Instance.Initialize(config);
This propject is crucial for my company and I am under pressure to come up with a solution. There is no time for package change or expirimentation. So as a workaround I set up a custom HTTP client for FFImageLoading to use, and set the connection timeout to 5 minutes. Seems to "hide" the issue for the time being. I post here the configuration change just in case someone comes to need:
var config = new FFImageLoading.Config.Configuration() { HttpHeadersTimeout = 300, HttpReadTimeout = 300, DiskCacheDuration = TimeSpan.FromDays(360d), TryToReadDiskCacheDurationFromHttpHeaders = false, ExecuteCallbacksOnUIThread = true, HttpClient = new HttpClient(new AndroidClientHandler() { ConnectTimeout = TimeSpan.FromMinutes(5), AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, }), }; ImageService.Instance.Initialize(config);
@nikossaperas It seems to me that this not only hides, but is the real solution to the problem: https://github.com/square/okhttp/issues/4110#issuecomment-402436150 https://github.com/square/okhttp/issues/6318
This solution is not working for me since my app is still crashing. Any other ideas or updates?
This library more likely is not maintained any more.
If your issue is in production try this (not tested): Use a timer with the timeout below the value on the code fragment above-say four(4) minutes. On timesout use ImageService.Instance.CancelWorkForView(MyImageView); // to cancel one image loading request or ImageService.Instance.SetPauseWork(true); // to cancel all image loading requests
It's an ungly and hacky solution that may not work after all. If still under development maybe use another package, not FFImageLoading.
Same here,
I have a lot of crashes on production. Any solution?