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

Switching a file to a different network during the upload process will cause the upload to terminate and require a long wait for error feedback. #2318

Closed
wahkim opened this issue Oct 29, 2024 · 1 comment

Comments

@wahkim
Copy link

wahkim commented Oct 29, 2024

Package

dio

Version

5.7.0

Operating-System

iOS

Adapter

Default Dio

Output of flutter doctor -v

[✓] Flutter (Channel stable, 3.22.2, on macOS 15.0.1 24A348 darwin-x64, locale zh-Hans-CN)
    • Flutter version 3.22.2 on channel stable at /Users/xxx3/FlutterSDK/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 761747bfc5 (5 months ago), 2024-06-05 22:15:13 +0200
    • Engine revision edd8546116
    • Dart version 3.4.3
    • DevTools version 2.34.3
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.


[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16A242d
    • CocoaPods version 1.15.2

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

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).

[✓] VS Code (version 1.94.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.98.0

[✓] Connected device (4 available)
    • LIN (mobile)      • 00008110-0010193C3E6A801E • ios            • iOS 18.0.1 22A3370
    • macOS (desktop)       • macos                     • darwin-x64     • macOS 15.0.1 24A348 darwin-x64
    • Chrome (web)          • chrome                    • web-javascript • Google Chrome 130.0.6723.70

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.

Dart Version

3.4.3

Steps to Reproduce

Switching a file to a different network during the upload process will cause the upload to terminate and require a long wait for error feedback.

Dio dio = new Dio();
      dio.httpClientAdapter = IOHttpClientAdapter(
        createHttpClient: () {
          final client = HttpClient();
          client.badCertificateCallback = (X509Certificate cert, String host, int port) {
            return true;
          };
          client.connectionTimeout = Duration(seconds: 5);
          return client;
        },
      );
      String? contentType = lookupMimeType(filePath);
      dio.options.contentType = contentType;
      File file = File(filePath);
      int fileLength = file.lengthSync();
      var response = await dio.put(
        url,
        data: file.openRead(),
        cancelToken: cancelToken,
        onSendProgress: (count, total) {
          debugPrint('onSendProgress count=${count}, total=${total}');
          onSendProgress?.call(count, total);
        },
        onReceiveProgress: (count, total) {
          debugPrint('onReceiveProgress count=${count}, total=${total}');
        },
        options: Options(contentType: contentType,  headers: {
          Headers.contentLengthHeader: fileLength, 
        }),
      );

      if (response.statusCode == 200) {
        // messageLog(uploadLog);
        if (successImp != null) {
          successImp(url, key);
        }
      } else {
        if (failImp != null) {
          failImp(response.statusCode.toString());
        }
      }
    } catch (e) {
      debugPrint('error=$e, url=$url');
      if (failImp != null) {
        failImp(e);
      }
    }

Expected Result

Switching a file to a different network during the upload process will cause the upload to terminate and require a long wait for error feedback.

Actual Result

Retransmit, or get error feedback quickly.

@wahkim wahkim added h: need triage This issue needs to be categorized s: bug Something isn't working labels Oct 29, 2024
@AlexV525
Copy link
Member

This is managed by the default HTTP client implementation of Dart. We're not network-status-awareness. Switching to other adapters like native_dio_adapter might help in this case.

@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 16, 2024
@AlexV525 AlexV525 added i: out of support and removed h: need triage This issue needs to be categorized s: bug Something isn't working labels Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants