From bdf4fa717402fde122b7fbb280b14f027da9f6c9 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Wed, 21 Oct 2026 09:24:17 +0200 Subject: [PATCH] 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 --- lib/core/errors.dart | 2 ++ test/core/network/network_provider_test.dart | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/core/errors.dart b/lib/core/errors.dart index e0c3e21f4..3c267a714 100644 --- a/lib/core/errors.dart +++ b/lib/core/errors.dart @@ -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; } diff --git a/test/core/network/network_provider_test.dart b/test/core/network/network_provider_test.dart index d93d45901..196431588 100644 --- a/test/core/network/network_provider_test.dart +++ b/test/core/network/network_provider_test.dart @@ -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;