Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AndroidClientHandler] Observe cancellation requests more
Context: dotnet#4550 It is possible that, in certain situations, a cancellation request arriving from code external to `AndroidClientHandler` will not be satisfied while starting the task to acquire connection status, because the cancellation request appears after handler already established connection to the remote host but before the request status is obtained. Failure to check that the cancellation was requested may result in the status retrieval task starting only to run into the issue that the `AndroidClientHandler` object itself is already disposed (since the cancellation request has been applied) and throw the `ObjectDisposedException` instead of cancelling the status request quietly. Note that this is likely happen only in situations when the application code aggressively cancels and collects (via calls to the `GC` class) `AndroidClientHandler` instances or in other situations which induce potential for timing issues in the TPL or `async/await` state machine, thus leading to possible race conditions there. This commit passes cancellation token to the task which runs the status request, thus preventing it from starting in the situation described above. The possibility of a race condition still remains, but is seriously reduced.
- Loading branch information