Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry logic not functioning as expected in RetryOptions #254

Open
binzheng opened this issue Sep 9, 2024 · 0 comments
Open

Retry logic not functioning as expected in RetryOptions #254

binzheng opened this issue Sep 9, 2024 · 0 comments
Labels
pending-triage Issue is pending triage pkg:retry

Comments

@binzheng
Copy link

binzheng commented Sep 9, 2024

Description:

I am using the RetryOptions class to handle retry logic in my code, but it seems the retry mechanism is not functioning as expected. Below is the code snippet I am using:

dart

final multiRequest = http.MultipartRequest('POST', _requestUri(path));
multiRequest.files.addAll(files);
if (fields != null) {
      multiRequest.fields.addAll(fields.toJson());
}
multiRequest.headers.addAll(
        _generateHttpHeader(transmissionType: transmissionType)..addAll({'Content-Type': 'multipart/form-data'}));
const r = RetryOptions(maxAttempts: 5);
final streamResponse = await r.retry(
  () async => await multiRequest.send(),
  retryIf: (e) => e is SocketException || e is TimeoutException,
  onRetry: (e) => logger.warning("onRetry: $e"),
);

When an exception occurs, the onRetry callback is executed only once, and the retryIf callback is also executed only once. Despite having set maxAttempts to 5, the retry mechanism does not retry the operation as expected. Instead, it fails after the first attempt.

Error Log:

csharp

flutter: [WARNING] 11:51:57.945 webapi_repository_impl.dart 120:30 in WebapiRepository.apiUpload.<fn>] onRetry: ClientException with SocketException: Operation timed out (OS Error: Operation timed out, errno = 60), address = aaa.xxx.jp, port = 60599, uri=https://aaa.xxx.jp/api/xxxxx/pdf?sendMail=true

Steps to Reproduce:

Execute the above code snippet with a setup that triggers a SocketException or TimeoutException.
Observe that retries are not performed as expected.
Expected Behavior:

The retry mechanism should retry the operation up to the specified number of attempts (maxAttempts) when a SocketException or TimeoutException occurs.

Additional Information:

Flutter version: 3.19.5
Dependencies:
http: 1.1.0
retry: 3.1.2
Please let me know if you need any additional information or if there is a fix available for this issue.

Thank you!

@binzheng binzheng added pending-triage Issue is pending triage pkg:retry labels Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-triage Issue is pending triage pkg:retry
Projects
None yet
Development

No branches or pull requests

1 participant