From 6ffecd2d5d8ae8f2bb7692ac29e2b1f27d253fe6 Mon Sep 17 00:00:00 2001 From: Mohamed Gawdat Date: Wed, 25 Nov 2026 17:33:55 +0300 Subject: [PATCH 1/3] fix: support Dio transformation timeouts What: Handle transformation timeouts as transient event-delivery failures, add regression tests, and test locked and latest Dio versions in CI. Why: Dio 5.10 added an enum value that made event processing fail to compile. Matching the new value by name preserves compatibility with older Dio versions. Await the initial flush in the cooldown test to avoid a timer race. How to test: Run flutter test and dart analyze with Dio 5.3.2 and 5.11.1. --- .github/workflows/pull-request.yml | 7 ++- lib/src/core/events/event_processor.dart | 7 +-- test/fg/flagsmith_experiments_test.dart | 62 +++++++++++++++++++++++- 3 files changed, 71 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 1eb7c4f..b80a4a5 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -28,7 +28,10 @@ jobs: tests: runs-on: ubuntu-latest - name: Flutter Test + name: Flutter Test (Dio ${{ matrix.dio }}) + strategy: + matrix: + dio: [locked, latest] steps: - uses: actions/checkout@v4 - uses: subosito/flutter-action@v2 @@ -36,6 +39,8 @@ jobs: flutter-version: ${{ env.FLUTTER_VERSION }} channel: stable - run: flutter pub get + - run: flutter pub upgrade dio + if: matrix.dio == 'latest' - run: flutter test # TODO https://github.com/Flagsmith/flagsmith-flutter-client/issues/57 diff --git a/lib/src/core/events/event_processor.dart b/lib/src/core/events/event_processor.dart index 0f953b9..bee8711 100644 --- a/lib/src/core/events/event_processor.dart +++ b/lib/src/core/events/event_processor.dart @@ -383,9 +383,10 @@ class EventProcessor { // A connection reset mid-request surfaces as an I/O exception // (SocketException or HttpException); encoding failures are Errors. return e.error is Exception && e.error is! FormatException; - case DioExceptionType.badCertificate: - case DioExceptionType.badResponse: - return false; + default: + // Dio 5.10.0 added transformTimeout. Match by name to keep older + // supported Dio versions compiling, and reject other error types. + return e.type.name == 'transformTimeout'; } } diff --git a/test/fg/flagsmith_experiments_test.dart b/test/fg/flagsmith_experiments_test.dart index ae58892..eb26c4a 100644 --- a/test/fg/flagsmith_experiments_test.dart +++ b/test/fg/flagsmith_experiments_test.dart @@ -755,6 +755,66 @@ void main() { expect(p.buffer, isEmpty); }); + // Resolve by name so these tests also compile with Dio before 5.10.0. + for (final type in DioExceptionType.values + .where((type) => type.name == 'transformTimeout')) { + test('When every response transformation times out, then batch is kept', + () async { + dio.interceptors.add(InterceptorsWrapper(onRequest: (options, h) { + h.reject(DioException(requestOptions: options, type: type)); + })); + + final p = processor(); + p.trackEvent(event: 'purchase'); + await p.flush(); + + expect(capture.requests.length, EventProcessor.maxAttempts); + expect(p.buffer.single['event'], 'purchase'); + }); + + test('When a transformation timeout precedes success, then delivered', + () async { + script([]); + var attempts = 0; + dio.interceptors.add(InterceptorsWrapper(onRequest: (options, h) { + if (attempts++ == 0) { + h.reject(DioException(requestOptions: options, type: type)); + } else { + h.next(options); + } + })); + + final p = processor(); + p.trackEvent(event: 'checkout'); + await p.flush(); + + expect(sentBatches(), [ + ['checkout'], + ['checkout'], + ]); + expect(p.buffer, isEmpty); + }); + } + + for (final type in [ + DioExceptionType.badCertificate, + DioExceptionType.badResponse, + ]) { + test('When a request fails with ${type.name}, then dropped without retry', + () async { + dio.interceptors.add(InterceptorsWrapper(onRequest: (options, h) { + h.reject(DioException(requestOptions: options, type: type)); + })); + + final p = processor(); + p.trackEvent(event: 'purchase'); + await p.flush(); + + expect(capture.requests.length, 1); + expect(p.buffer, isEmpty); + }); + } + for (final status in [408, 429, 502, 503, 504]) { test('When every attempt gets a $status, then batch is kept', () async { script([status, status, status]); @@ -999,7 +1059,7 @@ void main() { final p = processor(maxBuffer: 1, retryBackoff: 10); expect(p.holdCoolDown, 40); p.trackEvent(event: 'a'); - await Future.delayed(const Duration(milliseconds: 30)); + await p.flush(); expect(capture.requests.length, 3); p.trackEvent(event: 'b'); expect(capture.requests.length, 3, reason: 'held after the kept batch'); From a9eb008de782bcc523594bd78a354c1f02c42a22 Mon Sep 17 00:00:00 2001 From: Mohamed Gawdat Date: Wed, 25 Nov 2026 17:43:03 +0300 Subject: [PATCH 2/3] Limit Dio compatibility fix to event error handling What: Restore the existing CI workflow and tests. Why: Keep this change focused on the Dio transformation-timeout build error. How to test: Run the existing test suite and dart analyze with Dio 5.11.1. --- .github/workflows/pull-request.yml | 7 +-- test/fg/flagsmith_experiments_test.dart | 62 +------------------------ 2 files changed, 2 insertions(+), 67 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index b80a4a5..1eb7c4f 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -28,10 +28,7 @@ jobs: tests: runs-on: ubuntu-latest - name: Flutter Test (Dio ${{ matrix.dio }}) - strategy: - matrix: - dio: [locked, latest] + name: Flutter Test steps: - uses: actions/checkout@v4 - uses: subosito/flutter-action@v2 @@ -39,8 +36,6 @@ jobs: flutter-version: ${{ env.FLUTTER_VERSION }} channel: stable - run: flutter pub get - - run: flutter pub upgrade dio - if: matrix.dio == 'latest' - run: flutter test # TODO https://github.com/Flagsmith/flagsmith-flutter-client/issues/57 diff --git a/test/fg/flagsmith_experiments_test.dart b/test/fg/flagsmith_experiments_test.dart index eb26c4a..ae58892 100644 --- a/test/fg/flagsmith_experiments_test.dart +++ b/test/fg/flagsmith_experiments_test.dart @@ -755,66 +755,6 @@ void main() { expect(p.buffer, isEmpty); }); - // Resolve by name so these tests also compile with Dio before 5.10.0. - for (final type in DioExceptionType.values - .where((type) => type.name == 'transformTimeout')) { - test('When every response transformation times out, then batch is kept', - () async { - dio.interceptors.add(InterceptorsWrapper(onRequest: (options, h) { - h.reject(DioException(requestOptions: options, type: type)); - })); - - final p = processor(); - p.trackEvent(event: 'purchase'); - await p.flush(); - - expect(capture.requests.length, EventProcessor.maxAttempts); - expect(p.buffer.single['event'], 'purchase'); - }); - - test('When a transformation timeout precedes success, then delivered', - () async { - script([]); - var attempts = 0; - dio.interceptors.add(InterceptorsWrapper(onRequest: (options, h) { - if (attempts++ == 0) { - h.reject(DioException(requestOptions: options, type: type)); - } else { - h.next(options); - } - })); - - final p = processor(); - p.trackEvent(event: 'checkout'); - await p.flush(); - - expect(sentBatches(), [ - ['checkout'], - ['checkout'], - ]); - expect(p.buffer, isEmpty); - }); - } - - for (final type in [ - DioExceptionType.badCertificate, - DioExceptionType.badResponse, - ]) { - test('When a request fails with ${type.name}, then dropped without retry', - () async { - dio.interceptors.add(InterceptorsWrapper(onRequest: (options, h) { - h.reject(DioException(requestOptions: options, type: type)); - })); - - final p = processor(); - p.trackEvent(event: 'purchase'); - await p.flush(); - - expect(capture.requests.length, 1); - expect(p.buffer, isEmpty); - }); - } - for (final status in [408, 429, 502, 503, 504]) { test('When every attempt gets a $status, then batch is kept', () async { script([status, status, status]); @@ -1059,7 +999,7 @@ void main() { final p = processor(maxBuffer: 1, retryBackoff: 10); expect(p.holdCoolDown, 40); p.trackEvent(event: 'a'); - await p.flush(); + await Future.delayed(const Duration(milliseconds: 30)); expect(capture.requests.length, 3); p.trackEvent(event: 'b'); expect(capture.requests.length, 3, reason: 'held after the kept batch'); From 9080f79319eaf3bcfd7c9e34e3531382565d9da9 Mon Sep 17 00:00:00 2001 From: Mohamed Gawdat Date: Wed, 25 Nov 2026 17:52:06 +0300 Subject: [PATCH 3/3] fix: update Dio and handle transformation timeouts What: Require Dio ^5.11.1, update its lockfile entry, and explicitly handle DioExceptionType.transformTimeout in the event processor. Why: Handle every Dio error type so event processing compiles successfully. How to test: Run the existing Flutter tests and dart analyze with Dio 5.11.1. --- lib/src/core/events/event_processor.dart | 8 ++++---- pubspec.lock | 4 ++-- pubspec.yaml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/src/core/events/event_processor.dart b/lib/src/core/events/event_processor.dart index bee8711..d5fb283 100644 --- a/lib/src/core/events/event_processor.dart +++ b/lib/src/core/events/event_processor.dart @@ -376,6 +376,7 @@ class EventProcessor { case DioExceptionType.connectionTimeout: case DioExceptionType.sendTimeout: case DioExceptionType.receiveTimeout: + case DioExceptionType.transformTimeout: case DioExceptionType.connectionError: case DioExceptionType.cancel: return true; @@ -383,10 +384,9 @@ class EventProcessor { // A connection reset mid-request surfaces as an I/O exception // (SocketException or HttpException); encoding failures are Errors. return e.error is Exception && e.error is! FormatException; - default: - // Dio 5.10.0 added transformTimeout. Match by name to keep older - // supported Dio versions compiling, and reject other error types. - return e.type.name == 'transformTimeout'; + case DioExceptionType.badCertificate: + case DioExceptionType.badResponse: + return false; } } diff --git a/pubspec.lock b/pubspec.lock index 3e25a33..a74d192 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -173,10 +173,10 @@ packages: dependency: "direct main" description: name: dio - sha256: "5598aa796bbf4699afd5c67c0f5f6e2ed542afc956884b9cd58c306966efc260" + sha256: "852ec3b48cc431ac04fff978413c541502b67ffc3e26921e74e3d994694192c1" url: "https://pub.dev" source: hosted - version: "5.7.0" + version: "5.11.1" dio_web_adapter: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 80c4701..e1bd1d7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: sdk: flutter flutter_client_sse: ^2.0.0 collection: ^1.18.0 - dio: ^5.3.2 + dio: ^5.11.1 rxdart: ^0.28.0 shared_preferences: ^2.3.2 json_annotation: ^4.9.0