dart-neats icon indicating copy to clipboard operation
dart-neats copied to clipboard

Doesn't work with Riverpod

Open pishguy opened this issue 2 years ago • 3 comments

i implemented riverpod package on our application and after install and using this library and I get this error:

TimeoutException after 0:00:03.000000: Future not completed

And retry doesn't attempt again to send request

class LoginRepository {
  final Reader _reader;

  LoginRepository(this._reader);

  Future<LoginResponseStructure> getLoginResponse(String mobileNumber) async {
    try {
      const r = RetryOptions(maxAttempts: 3);
      final response = await r.retry(
        () => _reader(dioProvider)
            .post(
              Server.$signUP,
              queryParameters: {'mobile_number': mobileNumber},
              options: Options(
                headers: {'Content-Type': 'application/json'},
              ),
            )
            .timeout(const Duration(seconds: 30)),
        retryIf: (e) => e is SocketException || e is TimeoutException,
      );

      return LoginResponseStructure.fromJson(response.data as Map<String, dynamic>);
    } on DioError catch (e) {
      throw e.error as Object;
    }
  }
}

pishguy avatar Aug 15 '21 16:08 pishguy

Are you sure it's not a different timeout?

jonasfj avatar Nov 25 '21 10:11 jonasfj

@jonasfj yes

pishguy avatar May 09 '22 11:05 pishguy

Can you make a self-contained example.. maybe do .timeout(const Duration(seconds: 30)) and see if you can reproduce reliably, and insert some print statements in retryIf to see what it called with.

My two cents is that it's failing with another exception, or that something you've imported defines a TimeoutException different from the one in dart:async.

Or that retry is broken is some other way, that is independent on riverpod and can be reproduced by just trying to handle timeouts in general.

jonasfj avatar May 09 '22 12:05 jonasfj

If anyone can demonstrate a trivial example and find a bug in retry I down for fixing it. But realistically I doubt much progress will be made on this issue.

Its entirely likely that it's a different timeout in a microtask, or that all retries are exhausted.

jonasfj avatar Sep 12 '22 22:09 jonasfj