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

Download receiveTimeout #2022

Closed
QixianWu opened this issue Nov 2, 2023 · 6 comments · Fixed by #2029
Closed

Download receiveTimeout #2022

QixianWu opened this issue Nov 2, 2023 · 6 comments · Fixed by #2029
Labels
fixed p: dio Targeting `dio` package s: feature This issue indicates a feature request

Comments

@QixianWu
Copy link

QixianWu commented Nov 2, 2023

Package

dio

Version

5.3.3

Operating-System

Android

Output of flutter doctor -v

┌─────────────────────────────────────────────────────────┐
│ A new version of Flutter is available!                  │
│                                                         │
│ To update to the latest version, run "flutter upgrade". │
└─────────────────────────────────────────────────────────┘
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.13.6, on macOS 14.0 23A344 darwin-arm64, locale
    zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.1.1)
[✓] VS Code (version 1.77.1)
[✓] Connected device (4 available)

Dart Version

No response

Steps to Reproduce

In previous versions, it was only necessary to set the receiveTimeout of the Download Options to 0 to download without timeout. Now, after changing to the Duration type, the time cannot be unlimited

Future downloadFile(urlPath, savePath,
      {CancelToken? cancelToken, ProgressCallback? onReceiveProgress}) async {
    Response? response;
    response = await dio.download(urlPath, savePath,
        cancelToken: cancelToken,
        options: Options(receiveTimeout: Duration(seconds: 0)),
        onReceiveProgress: onReceiveProgress ??
            (int count, int total) {
              logI("$count $total");
            });
    return response;
  }

Expected Result

download success

Actual Result

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: DioException [receive timeout]: The request took longer than 0:00:00.000000 to receive data. It was aborted.

@QixianWu QixianWu added h: need triage This issue needs to be categorized s: bug Something isn't working labels Nov 2, 2023
@kuhnroyal
Copy link
Member

You should be able to set it to null now.

@QixianWu
Copy link
Author

QixianWu commented Nov 6, 2023

You should be able to set it to 'null' now.

I have tried to set it to 'null', but it defaults to using the 'receiveTimeout' of the option for the single instance 'dio', so my current method can only set it to a relatively large time

@kuhnroyal
Copy link
Member

Oh, right so you can not override it in the Options passed to a single request if you have a different duration set it in the BaseOptions?
You should be able to set it to null on the BaseOptions?

Do I understand this correctly?

@QixianWu
Copy link
Author

QixianWu commented Nov 7, 2023

Oh, right so you can not override it in the Options passed to a single request if you have a different duration set it in the BaseOptions? You should be able to set it to null on the BaseOptions?

Do I understand this correctly?

Yes, Unless a new Dio is instantiated. For me, the entire app uses the same single instance Dio, and the receiveTimeout set by the Base Options is 15 seconds.

@AlexV525
Copy link
Member

AlexV525 commented Nov 9, 2023

So the most straight-forward solution would be to ignore zero duration? @ueman

@kuhnroyal
Copy link
Member

Yea I agree

github-merge-queue bot pushed a commit that referenced this issue Nov 21, 2023
Resolves #2022.

### New Pull Request Checklist

- [x] I have read the
[Documentation](https://pub.dev/documentation/dio/latest/)
- [x] I have searched for a similar pull request in the
[project](https://github.com/cfug/dio/pulls) and found none
- [x] I have updated this branch with the latest `main` branch to avoid
conflicts (via merge from master or rebase)
- [x] I have added the required tests to prove the fix/feature I'm
adding
- [x] I have updated the documentation (if necessary)
- [x] I have run the tests without failures
- [x] I have updated the `CHANGELOG.md` in the corresponding package

### Additional context and info (if any)

I've found that the `IOHttpClientAdapter` uses `Stopwatch` to integrate
with `receiveTimeout`, which might cause infinity awaits if the stream
has no response forever. This might be the root cause of #1739.

https://github.com/cfug/dio/blob/78f3813a8d8948887198ef628e5a2e2039489b03/dio/lib/src/adapters/io_adapter.dart#L194-L200

---------

Signed-off-by: Alex Li <[email protected]>
@AlexV525 AlexV525 added s: feature This issue indicates a feature request p: dio Targeting `dio` package fixed and removed h: need triage This issue needs to be categorized s: bug Something isn't working labels Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed p: dio Targeting `dio` package s: feature This issue indicates a feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants