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.