Treat raw OSErrors as network errors

On iOS, dart:io fails setting TCP_NODELAY on a connection that was
already reset and throws a plain OSError instead of a SocketException.
The reachability probe rethrew it and the app showed an error dialog.

Closes #1397
This commit is contained in:
Roland Geider
2026-10-21 09:24:17 +02:00
parent f85142b45f
commit bdf4fa7174
2 changed files with 17 additions and 0 deletions

View File

@@ -65,6 +65,8 @@ ErrorSeverity classifyError(Object? error) {
bool isNetworkError(Object e) {
return e is http.ClientException ||
e is SocketException ||
// Raw from socket options, e.g. TCP_NODELAY on a reset connection on iOS
e is OSError ||
e is HandshakeException ||
e is TimeoutException;
}

View File

@@ -645,6 +645,21 @@ void main() {
expect(probeCount, greaterThan(afterInit));
});
group('default reachability check', () {
final probeUri = Uri.parse('https://wger.example/api/v2/version/');
test('a raw OSError from the socket counts as unreachable', () async {
// iOS fails setting TCP_NODELAY on an already reset connection, which
// dart:io throws as OSError instead of SocketException (flutter#1397)
final result = await http.runWithClient(
() => originalReachability(probeUri, null, const Duration(seconds: 1)),
() => MockClient((_) => throw const OSError('Invalid argument', 22)),
);
expect(result.reachable, isFalse);
});
});
group('ReachabilityReportingClient', () {
late _RecordingNetworkStatus status;