Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Start a http(s) request on Xamarin Android or iOS and the server side never returns a response. Disconnect network cable, or on a physical device change to Airplane Mode. The standing request does not trigger a disconnection immediatly.
Open attached solution
Run sample in an Android API 15 emulator
Let the sample run for 5 minutes, notice http requests are cancelled every 100 seconds
When a request has just started, disconnect network cable, notice the application does not detect the failure, the request is cancelled after 100 seconds.
I'm not entirely sure what could be done to improve this. I see no events on Android to be notified of when the network is disconnected, which means we're left with POSIX socket(2)/connect(2).
POSIX could error out, e.g. write(2) could error with ENETDOWN, but there's not necessarily any timeliness guarantee for when (if ever) write(2) would error out.
Which is a longwinded way of saying that I have no idea how to solve this, and timeouts are likely the sanest solution anyway.
It is possible to monitor the network connection in Android using the ConnectivityManager class (subject to some restrictions). See https://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html.
An Android application may also register a BroadcastReceiver, listening for `android.net.conn.CONNECTIVITY_CHANGE` actions. Note that starting in Android 7.0 this broadcast receiver must be dynamically registered at runtime.
Finally, one could also use the Firebase Job Dispatcher. This library will allow a background job to execute when network changes happen. The job could then take the appropriate action so that the App can handle the disconnected network.