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
It is possible for a request to be cancelled after it has already delivered its response. I have set up a custom Request class that overrides cancel() to support a cancel listener in addition to the response and error listeners. I have a scenario where as a response to a request, I issue a cancelAll to cancel all further requests. Perhaps 10% of the time I'm seeing the cancel listeners be notified of the very request that was already handled. It appears this is a race between the request handling thread issuing the cancelAll() and the volley worker thread removing the request from the queue after it was handled. Perhaps the state could be checked to not issue a call to cancel on requests that are already complete?
The text was updated successfully, but these errors were encountered:
Adding a cancel listener in a thread-safe way is actually fairly tricky. See issue #85 and PR #103 for a previous attempt at this. This remains an open feature request but we haven't implemented it yet.
In the mean time, if you are using Volley's default ResponseDelivery which dispatches responses on the main thread, then you could work around this by having whatever invokes your cancel listeners dispatch a runnable to the main thread which checks whether the request is complete and drops the event if so.
Thank you for the response. I did work around it by doing something similar to what you described. I just thought the call to cancel an already completed request was a bit odd so thought I'd let you know of the race condition. Thanks!
It is possible for a request to be cancelled after it has already delivered its response. I have set up a custom Request class that overrides cancel() to support a cancel listener in addition to the response and error listeners. I have a scenario where as a response to a request, I issue a cancelAll to cancel all further requests. Perhaps 10% of the time I'm seeing the cancel listeners be notified of the very request that was already handled. It appears this is a race between the request handling thread issuing the cancelAll() and the volley worker thread removing the request from the queue after it was handled. Perhaps the state could be checked to not issue a call to cancel on requests that are already complete?
The text was updated successfully, but these errors were encountered: