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

Issues with http2_adapter in dio causing HTTP/1.1 requests to fail and incorrect traffic type displayed in Flutter DevTools #2341

Closed
TheWalkingDead1024 opened this issue Dec 10, 2024 · 4 comments
Labels
i: out of support p: dependency Targeting packages that's used by dio packages p: http2_adapter Targeting `http2_adapter` package

Comments

@TheWalkingDead1024
Copy link

TheWalkingDead1024 commented Dec 10, 2024

Package

dio

Version

5.7.0

Operating-System

Android

Adapter

Http2Adapter

Output of flutter doctor -v

[✓] Flutter (Channel stable, 3.19.0, on macOS 14.5 23F79 darwin-arm64, locale zh-Hans-CN)
    • Flutter version 3.19.0 on channel stable at /Users/luhaobo/fvm/versions/3.19.0
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision bae5e49bc2 (10 months ago), 2024-02-13 17:46:18 -0800
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/luhaobo/Library/Android/sdk/
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/luhaobo/Library/Android/sdk/
    • Java binary at: /Users/luhaobo/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
    • All Android licenses accepted.

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

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

[✓] Android Studio (version 2024.1)
    • Android Studio at /Users/luhaobo/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.11+0-17.0.11b1207.24-11852314)

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

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 14.5 23F79 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 131.0.6778.109
    ! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area
      network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
    ! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area
      network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
    ! Error: Browsing on the local area network for 鲁好波 iPhone 13 Pro (2700). Ensure the device is unlocked and attached with a cable or associated with
      the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
    ! Error: Browsing on the local area network for 鸣人的iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local
      area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

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

• No issues found!

Dart Version

3.3.0

Steps to Reproduce

  1. Set up dio with http2_adapter as follows:
   final dio = Dio();
   dio.httpClientAdapter = Http2Adapter(
     ConnectionManager(
       idleTimeout: 10000,
     ),
   );
  1. Perform a HTTP/1.1 request using dio.
  2. Perform a HTTP/2 request using dio.
  3. Observe the traffic type in Flutter DevTools.

Expected Result

HTTP/1.1 requests should be handled correctly without failing, and the network traffic should be appropriately categorized and displayed in Flutter DevTools.

Actual Result

HTTP/1.1 requests fail when using http2_adapter, and the network traffic is incorrectly displayed as WebSocket traffic in Flutter DevTools.
a0ed2302-0158-4692-bd16-30b1d2402aac

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

Please provide a minimal reproducible example. We have a test to make sure that the adapter works with non-TLS requests and HTTP/1.x responses.

@AlexV525 AlexV525 added the h: need more info Further information is requested label Dec 16, 2024
@SmartVive
Copy link

void main() async {
  final dio = Dio()
    ..options.baseUrl = 'http://pub.dev'
    ..interceptors.add(LogInterceptor())
    ..httpClientAdapter = Http2Adapter(
      ConnectionManager(idleTimeout: const Duration(seconds: 10)),
    );

  Response<String> response;
  response = await dio.get('/?xx=6');
  for (final e in response.redirects) {
    print('redirect: ${e.statusCode} ${e.location}');
  }
  print(response.data);
}

result:

*** Request ***
uri: http://pub.dev/?xx=6
method: GET
responseType: ResponseType.plain
followRedirects: true
persistentConnection: true
connectTimeout: null
sendTimeout: null
receiveTimeout: null
receiveDataWhenStatusError: true
extra: {}
headers:

Unhandled exception:
DioException [unknown]: null
Error: HTTP/2 error: Connection error: Connection is being forcefully terminated. (errorCode: 10)
#0      DioMixin.fetch (package:dio/src/dio_mixin.dart:520:7)
<asynchronous suspension>
#1      main (package:dio_example/http2_adapter.dart:13:14)
<asynchronous suspension>
*** DioException ***:
uri: http://pub.dev/?xx=6
DioException [unknown]: null
Error: HTTP/2 error: Connection error: Connection is being forcefully terminated. (errorCode: 10)
[√] Flutter (Channel stable, 3.24.5, on Microsoft Windows [Version 10.0.19045.5247], locale zh-CN)
    • Flutter version 3.24.5 on channel stable at C:\Users\Mountains\AppData\Local\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision dec2ee5c1f (6 weeks ago), 2024-11-13 11:13:06 -0800
    • Engine revision a18df97ca5
    • Dart version 3.5.4
    • DevTools version 2.37.3
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at C:\Users\Mountains\AppData\Local\Android\sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: C:\Program Files\Android\Android Studio1\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0--11572160)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.10.1)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.10.34928.147
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2024.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 21.0.3+-12282718-b509.11)

[√] Android Studio (version 2024.1)
    • Android Studio at C:\Program Files\Android\Android Studio1
    • 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
    • android-studio-dir = C:\Program Files\Android\Android Studio1
    • Java version OpenJDK Runtime Environment (build 17.0.10+0--11572160)

[√] Connected device (4 available)
    • IN2010 (mobile)   • 192.168.6.100:43219 • android-arm64  • Android 11 (API 30)
    • Windows (desktop) • windows             • windows-x64    • Microsoft Windows [Version 10.0.19045.5247]
    • Chrome (web)      • chrome              • web-javascript • Google Chrome 131.0.6778.205
    • Edge (web)        • edge                • web-javascript • Microsoft Edge 131.0.2903.112

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

• No issues found!

https://github.com/cfug/dio/blob/main/example_dart/lib/http2_adapter.dart
only modify https://pub.dev to http://pub.dev
http2_adapter can process http?
@AlexV525

@SmartVive
Copy link

SmartVive commented Dec 29, 2024 via email

@AlexV525
Copy link
Member

Related to dart-lang/http#1383.

@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 30, 2024
@AlexV525 AlexV525 added i: out of support p: http2_adapter Targeting `http2_adapter` package p: dependency Targeting packages that's used by dio packages and removed h: need more info Further information is requested h: need triage This issue needs to be categorized s: bug Something isn't working labels Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i: out of support p: dependency Targeting packages that's used by dio packages p: http2_adapter Targeting `http2_adapter` package
Projects
None yet
Development

No branches or pull requests

3 participants