devtools icon indicating copy to clipboard operation
devtools copied to clipboard

Flutter devtools could not preview http request when debug in remote android device

Open StitchC opened this issue 1 year ago • 7 comments

Steps to reproduce

  1. Flutter run on a remote machine connect with usb
  2. Open devtool in Android Studio
  3. Select network tab and preview
  4. The network show all request type is socket not http request

Expected results

  1. show http requset header, body and response like use simulator

Actual results

all http request display type is "socket" image

Code sample

Code sample
[Paste your code here]

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.24.1, on macOS 14.6 23G80 darwin-arm64 (Rosetta), locale zh-Hans-CN)
    • Flutter version 3.24.1 on channel stable at
      /Users/chenrunsheng/Documents/flutter_sdk_collection/versions/3.24.1
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5874a72aa4 (2 周前), 2024-08-20 16:46:00 -0500
    • Engine revision c9b9d5780d
    • Dart version 3.5.1
    • DevTools version 2.37.2

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /Users/chenrunsheng/Library/Android/sdk
    • Platform android-34, build-tools 35.0.0
    • Java binary at: /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.app/Contents/Developer
    • Build 15F31d
    ! CocoaPods 1.11.3 out of date (1.13.0 is recommended).
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/to/platform-plugins
      To update CocoaPods, see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods

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

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

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

[!] Proxy Configuration
    • HTTP_PROXY is set
    ! NO_PROXY is not set

[✓] Connected device (4 available)
    • TC26 (mobile)                   • 22185523023281        • android-arm64  • Android 11 (API 30)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 14.6 23G80 darwin-arm64
      (Rosetta)
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 14.6 23G80 darwin-arm64
      (Rosetta)
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 128.0.6613.120

[!] Network resources
    ✗ A network error occurred while checking "https://pub.dev/": Connection reset by peer

! Doctor found issues in 3 categories.

StitchC avatar Sep 06 '24 07:09 StitchC

@bkonyi I know you recently made some fixes to the Network page. Is this what we expect to be seeing here? Thanks!

elliette avatar Sep 27 '24 20:09 elliette

@darshankawar are you using package:http or dart:io's HttpClient to make your requests? If not, they're not available through the network profiler.

bkonyi avatar Sep 27 '24 20:09 bkonyi

I have the same problem, i am use 'package:dio/dio.dart' And i try using dart:io's HttpClient but the error persist

LiamMarega avatar Oct 03 '24 19:10 LiamMarega

Same issue using dio package, any help ?

tuannvm2109 avatar Oct 07 '24 07:10 tuannvm2109

https://github.com/flutter/devtools/issues/8380#issuecomment-2393929155 @bkonyi I saw this reply, do you mean it's a dependency library issue rather than a devtool issue?

StitchC avatar Oct 15 '24 06:10 StitchC

I was trying both with package:http and dart:io and my problem is not solved

LiamMarega avatar Oct 15 '24 14:10 LiamMarega

#8380 (comment) @bkonyi I saw this reply, do you mean it's a dependency library issue rather than a devtool issue?

Potentially. package:http definitely works, and so does dart:io, but I'm not sure about package:dio. All of the HTTP libraries listed here will also work.

All of the HTTP logging functionality is currently built on dart:io's HttpClient, so if you're using an HTTP library that doesn't use HttpClient as the HTTP client, you might only see SOCKET events in the profiler if the HTTP library is using dart:io's Socket to make the HTTP connect. If the HTTP library is using FFI and doesn't use package:http_profile to provide profiling details, those requests won't be available to DevTools either.

If you set HttpClient.enableTimelineLogging to true as the first line in main(), HTTP profiling will be enabled before any HTTP requests are made by your program and DevTools should be able to display them if they're being made through HttpClient. If you're still not seeing requests, we really need a small reproduction test case for us to be able to properly debug this.

bkonyi avatar Oct 15 '24 14:10 bkonyi

@bkonyi tried with http package still its not working and HttpClient.enableTimelineLogging to true as the first line of main().

The testing was done in counter app please check screenshots. Screenshot from 2024-10-25 16-38-39 Screenshot from 2024-10-25 16-38-31 Screenshot from 2024-10-25 16-38-13 Screenshot from 2024-10-25 16-38-04

mithun-itspe avatar Oct 25 '24 10:10 mithun-itspe

I think I've found the cause of this issue and uploaded a fix in https://github.com/flutter/devtools/pull/8860.

TL;DR: it looks like there's a possible race condition that can cause HTTP requests to be missed by DevTools, particularly when the network channel between DevTools and the target application is slow. This is likely why some users seem to encounter the issue consistently where others can't reproduce it.

I hope to land the above PR and get it cherry picked into the next stable release.

bkonyi avatar Feb 10 '25 17:02 bkonyi