Ffimageloading: ObjectExtensions.TryDispose (System.IDisposable obj) exception

Created on 30 Sep 2020  路  5Comments  路  Source: luberda-molinet/FFImageLoading

馃悰 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.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

Most helpful comment

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);

All 5 comments

@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.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vime-o picture vime-o  路  5Comments

Pinox picture Pinox  路  5Comments

matheusvelloso picture matheusvelloso  路  4Comments

abenedykt picture abenedykt  路  3Comments

lhughey picture lhughey  路  3Comments