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 causes Timeout exception #2034

Closed
Clon1998 opened this issue Nov 19, 2023 · 7 comments · Fixed by #2036
Closed

Download causes Timeout exception #2034

Clon1998 opened this issue Nov 19, 2023 · 7 comments · Fixed by #2036
Labels
fixed p: dio Targeting `dio` package platform: io s: bug Something isn't working

Comments

@Clon1998
Copy link

Clon1998 commented Nov 19, 2023

Package

dio

Version

5.3.3

Operating-System

Android

Output of flutter doctor -v

[✓] Flutter (Channel stable, 3.13.6, on macOS 13.5.2 22G91 darwin-arm64, locale de-DE)
    • Flutter version 3.13.6 on channel stable at /Users/patrick/development/sdks/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ead455963c (8 weeks ago), 2023-09-26 18:28:17 -0700
    • Engine revision a794cf2681
    • Dart version 3.1.3
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/patrick/development/sdks/android
    • Platform android-34, build-tools 33.0.2
    • ANDROID_SDK_ROOT = /Users/patrick/development/sdks/android
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A240d
    • CocoaPods version 1.13.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.1)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 76.0.4
    • Dart plugin version 232.9559.10

[✓] VS Code (version 1.84.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (4 available)
    • sdk gphone64 arm64 (mobile)         • emulator-5554             • android-arm64  • Android 12 (API 32) (emulator)
    • iPhone von Patrick Schmidt (mobile) • 00008110-000449CE2699801E • ios            • iOS 17.1.1 21B91
    • macOS (desktop)                     • macos                     • darwin-arm64   • macOS 13.5.2 22G91 darwin-arm64
    • Chrome (web)                        • chrome                    • web-javascript • Google Chrome 119.0.6045.159

[✓] Network resources
    • All expected network resources are available.
• No issues found!

Dart Version

3.1.3

Steps to Reproduce

  1. Create a Dio.download() request with a receiveTimeout set that will trigger (In my case the download takes 10s so I set it to 3s).
  2. Start downloading the file.

Expected Result

As stated in the readme and the code itself, dio should only throw a TimeoutException based on the receiveTimeout defined "timeout during data transfer of each bytes and not the overall timing during the receiving.".

Therefore, the download should finish without any issue since bytes are constantly received.

Actual Result

The download is stopped due to a TimeoutException of the receiveTimeout. However, using the onReceiveProgress callback of the download method, I can see that progress and therefore bytes are received constantly.

@Clon1998 Clon1998 added h: need triage This issue needs to be categorized s: bug Something isn't working labels Nov 19, 2023
@AlexV525 AlexV525 added p: dio Targeting `dio` package platform: io and removed h: need triage This issue needs to be categorized labels Nov 19, 2023
@AlexV525

This comment was marked as off-topic.

@Clon1998
Copy link
Author

As I stated in #2029 (comment) (additional context).

I don't understand how this is related to this problem. Do you mind explaining it to me?

@kuhnroyal
Copy link
Member

We are currently trying to fix a couple things but it does not seem to be related directly.

As stated in the readme and the code itself, dio should only throw a TimeoutException based on the receiveTimeout defined "timeout during data transfer of each bytes and not the overall timing during the receiving.".

I was not aware of this and I have not seen any code which would support this.
AFAIK, the receiveTimeout is measured until the first frame/chunk is received.

@AlexV525
Copy link
Member

Could you provide a reproducible URL or example?

@AlexV525 AlexV525 added the h: need more info Further information is requested label Nov 24, 2023
@Clon1998
Copy link
Author

Could you provide a reproducible URL or example?

Sure,
here is a somewhat minimal example, downloading one of the repos of cfug. You might need to adjust the timeout, for my connection 5 sec is enough to trigger the behavior.

void dummyDownload() async {
  final tmpDir = await getTemporaryDirectory();
  final File file = File('${tmpDir.path}/dummy.zip');

  var dio = Dio(BaseOptions(
    connectTimeout: Duration(seconds: 5),
    receiveTimeout: Duration(seconds: 5),
  ));

  // Some file that is rather "large" and takes longer to download
  var uri = "https://github.com/cfug/flutter.cn/archive/refs/heads/main.zip";
  
  var response = await dio.download(
    uri,
    file.path,
    onReceiveProgress: (received, total) {
      print('Received: $received, Total: $total');
    },
  );
  print('Download is done: ${response.statusCode}');
}

@AlexV525 AlexV525 removed the h: need more info Further information is requested label Nov 24, 2023
@AlexV525
Copy link
Member

Sure, here is a somewhat minimal example, downloading one of the repos of cfug.

Thanks. I can easily reproduce the issue with your example.

@AlexV525
Copy link
Member

This is caused by a duplicate timeout handler in the DioForNative.download implementation.

final timeout = response.requestOptions.receiveTimeout;
if (timeout != null) {
future = future.timeout(timeout).catchError(
(dynamic e, StackTrace s) async {
await subscription.cancel();
await closeAndDelete();
if (e is TimeoutException) {
throw DioException.receiveTimeout(

@AlexV525 AlexV525 mentioned this issue Nov 24, 2023
7 tasks
github-merge-queue bot pushed a commit that referenced this issue Nov 26, 2023
#2029 (comment)
- Possibly fixes #1739
- Fixes #2034

### 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

---------

Signed-off-by: Alex Li <[email protected]>
@AlexV525 AlexV525 added the fixed label Nov 26, 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 platform: io s: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants