Closed wadebaird closed 4 years ago
I confirm we have the exact same issue. We are executing the authentication request immediately after decryption using TouchId, and this worked until the last update. We made a workaround for this particular case, by delaying the request a few milliseconds, so it executes after the app regains "foreground" state, but this is definitely not ideal.
I am having this issue when iOS prompts the user to accept the required permissions. I've put a work around in to catch the exception and re-initiate the HTTP call if the caught exception is a TaskCanceledException, but this is not ideal.
I am closing the issues since we provided a workaround to stop this behavior from happening in https://github.com/xamarin/xamarin-macios/pull/6918
The issue is that we added this workaround because the mono runtime has issues with the ThreadPool in certain situations in which a request is performed and the application is moved to the background. In that case, we cancel the task so that we are in a known state and we can recover.
The workaround is a temporary fix until the mono team fixes the issue. But if you do not want the new behavior, please take a look at the new property added in the PR mentioned above and voluntarily make your HttpClient not to cancel requests (which is something that, for small requests, will work correctly).
I realize the root of this issue is most likely related to https://github.com/xamarin/xamarin-macios/issues/6443 and https://github.com/xamarin/xamarin-macios/pull/5463, however the application in this case is not in the background. In addition, I also think this is probably not the most ideal breaking change to make, especially since it immediately cancels all http calls when an app is placed in the background (such as simply swiping up from the bottom of the phone to load the iPhones bottom menu). This behavior will cause everyone to implement the background session handler for ALL http calls in order to prevent their simple calls from being cancelled, or simply go back to the version of Xamarin.Forms before this change was made.
Steps to Reproduce
Expected Behavior
No CanceledTaskException occurs (there is no real behavior in this repro as I minimized the code and project down to the bare minimum.
Actual Behavior
TaskCanceledException occurs on the Http.GetAsync call at callstack:
Environment
Build Logs
N/A
Example Project (If Possible)
CanceledTaskExceptionRepro.zip