You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AsyncHttpResponseHandler.ResponderHandler uses a WeakReference to AsyncHttpResponseHandler. When using the library as documented using a anonymous response handler, a race condition occurs between the garbage collector and AsyncHttpResponseHandler.ResponderHandler
In this scenario only AsyncHttpRequest keeps a strong reference to the AsyncHttpResponseHandler, at the end of it's run method it sends a message through the handler and then the run methods finishes. At this point the AsyncHttpRequest is garbage and since it is the only one holding a strong reference to it, so is the AsyncHttpResponseHandler. If the GC runs between the run method finishing and handleMessage in AsyncHttpResponseHandler.ResponderHandler retrieving the AsyncHttpResponseHandler from the WeakReference (you can simulate this by inserting a System.gc at the top of handleMessage) the weak reference is null and handleMessage cannot be called.
The result of this is that in some scenario's a HTTP request never gets a callback. neither a failure nor a success. This occured when I was using the lib to load a lot of images on a fast network connection, some never succeeded or failed so no retry was performed either.
The text was updated successfully, but these errors were encountered:
Hi @Aaargh20318, this is long known issue, and it should be fixed by merge ( 5ee354d ) done today, can you please verify ? I've got no time to deeply analyse memory model now.
Thank you anyway for your analysis, it's greatly appreciated. 👍
AsyncHttpResponseHandler.ResponderHandler uses a WeakReference to AsyncHttpResponseHandler. When using the library as documented using a anonymous response handler, a race condition occurs between the garbage collector and AsyncHttpResponseHandler.ResponderHandler
In this scenario only AsyncHttpRequest keeps a strong reference to the AsyncHttpResponseHandler, at the end of it's run method it sends a message through the handler and then the run methods finishes. At this point the AsyncHttpRequest is garbage and since it is the only one holding a strong reference to it, so is the AsyncHttpResponseHandler. If the GC runs between the run method finishing and handleMessage in AsyncHttpResponseHandler.ResponderHandler retrieving the AsyncHttpResponseHandler from the WeakReference (you can simulate this by inserting a System.gc at the top of handleMessage) the weak reference is null and handleMessage cannot be called.
The result of this is that in some scenario's a HTTP request never gets a callback. neither a failure nor a success. This occured when I was using the lib to load a lot of images on a fast network connection, some never succeeded or failed so no retry was performed either.
The text was updated successfully, but these errors were encountered: