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

Error connecting to the service protocol: failed to connect. #78

Closed
wilsonowilson opened this issue Aug 30, 2021 · 17 comments
Closed

Error connecting to the service protocol: failed to connect. #78

wilsonowilson opened this issue Aug 30, 2021 · 17 comments

Comments

@wilsonowilson
Copy link

wilsonowilson commented Aug 30, 2021

I've seen this error a lot lately. Whenever I try to attach Vscode to my Nativeshell app, this error is returned:

Error connecting to the service protocol: failed to connect to http://127.0.0.1:49925/wGGO2vRhFfw=/.

Running a normal Flutter app works fine. Cleaning flutter and restarting my computer has no effect. It seems to randomly start and stop working.

@knopp
Copy link
Contributor

knopp commented Aug 30, 2021

is the URL same as the URL printed when you run the app (cargo run)?

@wilsonowilson
Copy link
Author

wilsonowilson commented Aug 30, 2021

Oh it's not the same. The port is different

@knopp
Copy link
Contributor

knopp commented Aug 30, 2021

Which flutter version are you using? There was a regression recently in flutter tool debug attach caused by NNBD migration, but that should be resolved in latest master.

@wilsonowilson
Copy link
Author

I'm on Flutter 2.6.0-1.0.pre.108 from 2 days ago.

@wilsonowilson
Copy link
Author

I've also noticed that the last three digits of the port change randomly every time I try to attach vscode.

The vmservice file contains the exact same url that Nativeshell writes, but for some reason, flutter uses a different one.

@wilsonowilson
Copy link
Author

I should also mention that this behavior isn't specific to my project. All nativeshell apps, including the example project, don't work. Normal flutter apps do.

@knopp
Copy link
Contributor

knopp commented Sep 2, 2021

So flutter is trying to attach to different port than the vmservice file? That looks like a bug in flutter tool. I'll see if I can reproduce this.

@knopp
Copy link
Contributor

knopp commented Sep 2, 2021

Can you try the following?

In one terminal

cargo run

In second

flutter attach -v -d macos --debug-url <http url printed during cargo run>

and post here the logs from flutter attach?

@wilsonowilson
Copy link
Author

Here are the logs

[ +135 ms] executing: sysctl hw.optional.arm64
[  +34 ms] Exit code 0 from: sysctl hw.optional.arm64
[   +3 ms] hw.optional.arm64: 1
[   +9 ms] executing: [/Users/wilson/Developer/SDK/flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[  +29 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[        ] 334c95dbd919db697d849acad71a1d101d515181
[   +1 ms] executing: [/Users/wilson/Developer/SDK/flutter/] git tag --points-at 334c95dbd919db697d849acad71a1d101d515181
[  +68 ms] Exit code 0 from: git tag --points-at 334c95dbd919db697d849acad71a1d101d515181
[   +2 ms] executing: [/Users/wilson/Developer/SDK/flutter/] git describe --match *.*.* --long --tags 334c95dbd919db697d849acad71a1d101d515181
[  +53 ms] Exit code 0 from: git describe --match *.*.* --long --tags 334c95dbd919db697d849acad71a1d101d515181
[        ] 2.6.0-0.0.pre-161-g334c95dbd9
[  +12 ms] executing: [/Users/wilson/Developer/SDK/flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[  +17 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/master
[        ] executing: [/Users/wilson/Developer/SDK/flutter/] git ls-remote --get-url origin
[  +15 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[ +139 ms] Unable to locate an Android SDK.
[  +11 ms] executing: [/Users/wilson/Developer/SDK/flutter/] git rev-parse --abbrev-ref HEAD
[  +24 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] master
[  +10 ms] executing: sw_vers -productName
[  +23 ms] Exit code 0 from: sw_vers -productName
[        ] macOS
[        ] executing: sw_vers -productVersion
[  +17 ms] Exit code 0 from: sw_vers -productVersion
[        ] 12.0
[        ] executing: sw_vers -buildVersion
[  +18 ms] Exit code 0 from: sw_vers -buildVersion
[        ] 21A5304g
[  +78 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +3 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +50 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[        ] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[        ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'PubDependencies' is not required, skipping update.
[  +21 ms] executing: sysctl hw.optional.arm64
[  +10 ms] Exit code 0 from: sysctl hw.optional.arm64
[        ] hw.optional.arm64: 1
[        ] executing: /usr/bin/arch -arm64e xcrun xcodebuild -version
[ +125 ms] Exit code 0 from: /usr/bin/arch -arm64e xcrun xcodebuild -version
[        ] Xcode 13.0
           Build version 13A5154h
[   +1 ms] objc[59042]: Class AMSupportURLConnectionDelegate is implemented in both /usr/lib/libauthinstall.dylib (0x201ec5460) and
/Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x10a4942c8). One of the two will be used. Which
one is undefined.
           objc[59042]: Class AMSupportURLSession is implemented in both /usr/lib/libauthinstall.dylib (0x201ec54b0) and
           /Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x10a494318). One of the two will be
           used. Which one is undefined.
[ +187 ms] Connecting to service protocol: http://127.0.0.1:62619/wwFZgAUGELw=/
[ +231 ms] Launching a Dart Developer Service (DDS) instance at http://127.0.0.1:0, connecting to VM service at
http://127.0.0.1:62619/wwFZgAUGELw=/.
[ +178 ms] DDS is listening at http://127.0.0.1:62662/7BApDUaiM3E=/.
[  +95 ms] Successfully connected to service protocol: http://127.0.0.1:62619/wwFZgAUGELw=/
[  +36 ms] DevFS: Creating new filesystem on the device (null)
[  +26 ms] DevFS: Created new filesystem on the device (file:///var/folders/nr/h5fpm1zn3y98b4skkg8l46gw0000gn/T/velicour2tZ5PF/velicour/)
[   +2 ms] Updating assets
[ +172 ms] Syncing files to device macOS...
[   +2 ms] <- reset
[        ] Compiling dart to kernel with 0 updated files
[   +9 ms] /Users/wilson/Developer/SDK/flutter/bin/cache/dart-sdk/bin/dart --disable-dart-dev
/Users/wilson/Developer/SDK/flutter/bin/cache/artifacts/engine/darwin-x64/frontend_server.dart.snapshot --sdk-root
/Users/wilson/Developer/SDK/flutter/bin/cache/artifacts/engine/common/flutter_patched_sdk/ --incremental --target=flutter
--debugger-module-names --experimental-emit-debug-metadata --output-dill
/var/folders/nr/h5fpm1zn3y98b4skkg8l46gw0000gn/T/flutter_tools.CYkV6Y/flutter_tool.i3EO9b/app.dill --packages
/Users/wilson/Developer/Projects/velicour/.dart_tool/package_config.json -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts
--track-widget-creation --filesystem-scheme org-dartlang-root --initialize-from-dill build/cache.dill.track.dill --flutter-widget-cache
--enable-experiment=alternative-invalidation-strategy
[  +28 ms] <- compile package:velicour/main.dart
[+1489 ms] Activating Dart DevTools...
[+3261 ms] Activating Dart DevTools... (completed in 3.2s)
[+3397 ms] Updating files.
[   +1 ms] DevFS: Sync finished
[   +2 ms] Syncing files to device macOS... (completed in 8.2s)
[   +4 ms] Synced 0.0MB.
[   +3 ms] <- accept
[   +3 ms] Connected to _flutterView/0x7ff3ad877e20.
[  +24 ms] Flutter run key commands.
[   +3 ms] r Hot reload. 🔥🔥🔥
[   +9 ms] R Hot restart.
[        ] h List all available interactive commands.
[   +2 ms] d Detach (terminate "flutter run" but leave application running).
[        ] c Clear the screen
[        ] q Quit (terminate the application on the device).
[        ] 💪 Running with sound null safety 💪
[   +2 ms] An Observatory debugger and profiler on macOS is available at: http://127.0.0.1:62662/7BApDUaiM3E=/
[   +3 ms] The Flutter DevTools debugger and profiler on macOS is available at: http://127.0.0.1:9101?uri=http://127.0.0.1:62662/7BApDUaiM3E=/

It suddenly started working again after doing nothing for a few hours. But the problem usually reoccurs after a while. I'll post the logs once I face it again.

@wilsonowilson
Copy link
Author

Just started facing this issue again. The logs are pretty synonymous with the previous logs.

flutter attach -v -d macos --debug-url http://127.0.0.1:50445/8Yi_Kjwp5QU=/
[ +136 ms] executing: sysctl hw.optional.arm64
[  +32 ms] Exit code 0 from: sysctl hw.optional.arm64
[   +3 ms] hw.optional.arm64: 1
[   +9 ms] executing: [/Users/wilson/Developer/SDK/flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[  +39 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[        ] 334c95dbd919db697d849acad71a1d101d515181
[   +1 ms] executing: [/Users/wilson/Developer/SDK/flutter/] git tag --points-at 334c95dbd919db697d849acad71a1d101d515181
[  +83 ms] Exit code 0 from: git tag --points-at 334c95dbd919db697d849acad71a1d101d515181
[   +2 ms] executing: [/Users/wilson/Developer/SDK/flutter/] git describe --match *.*.* --long --tags 334c95dbd919db697d849acad71a1d101d515181
[  +50 ms] Exit code 0 from: git describe --match *.*.* --long --tags 334c95dbd919db697d849acad71a1d101d515181
[        ] 2.6.0-0.0.pre-161-g334c95dbd9
[  +12 ms] executing: [/Users/wilson/Developer/SDK/flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[  +17 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/master
[        ] executing: [/Users/wilson/Developer/SDK/flutter/] git ls-remote --get-url origin
[  +18 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[ +153 ms] Unable to locate an Android SDK.
[  +10 ms] executing: [/Users/wilson/Developer/SDK/flutter/] git rev-parse --abbrev-ref HEAD
[  +21 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[   +1 ms] master
[   +8 ms] executing: sw_vers -productName
[  +29 ms] Exit code 0 from: sw_vers -productName
[        ] macOS
[        ] executing: sw_vers -productVersion
[  +22 ms] Exit code 0 from: sw_vers -productVersion
[        ] 12.0
[        ] executing: sw_vers -buildVersion
[  +23 ms] Exit code 0 from: sw_vers -buildVersion
[        ] 21A5304g
[  +65 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +3 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +48 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[        ] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[        ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'PubDependencies' is not required, skipping update.
[  +20 ms] executing: sysctl hw.optional.arm64
[  +12 ms] Exit code 0 from: sysctl hw.optional.arm64
[        ] hw.optional.arm64: 1
[        ] executing: /usr/bin/arch -arm64e xcrun xcodebuild -version
[ +127 ms] Exit code 0 from: /usr/bin/arch -arm64e xcrun xcodebuild -version
[        ] Xcode 13.0
           Build version 13A5154h
[   +1 ms] objc[24804]: Class AMSupportURLConnectionDelegate is implemented in both /usr/lib/libauthinstall.dylib (0x215fa9460) and
/Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x106f942c8). One of the two will be used.
Which one is undefined.
           objc[24804]: Class AMSupportURLSession is implemented in both /usr/lib/libauthinstall.dylib (0x215fa94b0) and
           /Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x106f94318). One of the two will
           be used. Which one is undefined.
[ +182 ms] Connecting to service protocol: http://127.0.0.1:50445/8Yi_Kjwp5QU=/
[ +255 ms] Launching a Dart Developer Service (DDS) instance at http://127.0.0.1:0, connecting to VM service at
http://127.0.0.1:50445/8Yi_Kjwp5QU=/.
[ +139 ms] DDS is listening at http://127.0.0.1:50468/7EpInU_Pc7Q=/.
[  +76 ms] Successfully connected to service protocol: http://127.0.0.1:50445/8Yi_Kjwp5QU=/
[  +48 ms] DevFS: Creating new filesystem on the device (null)
[  +22 ms] DevFS: Created new filesystem on the device (file:///var/folders/nr/h5fpm1zn3y98b4skkg8l46gw0000gn/T/velicourv8LILc/velicour/)
[   +2 ms] Updating assets
[ +187 ms] Syncing files to device macOS...
[   +2 ms] <- reset
[        ] Compiling dart to kernel with 0 updated files
[   +9 ms] /Users/wilson/Developer/SDK/flutter/bin/cache/dart-sdk/bin/dart --disable-dart-dev
/Users/wilson/Developer/SDK/flutter/bin/cache/artifacts/engine/darwin-x64/frontend_server.dart.snapshot --sdk-root
/Users/wilson/Developer/SDK/flutter/bin/cache/artifacts/engine/common/flutter_patched_sdk/ --incremental --target=flutter
--debugger-module-names --experimental-emit-debug-metadata --output-dill
/var/folders/nr/h5fpm1zn3y98b4skkg8l46gw0000gn/T/flutter_tools.l6nQ12/flutter_tool.AeCypx/app.dill --packages
/Users/wilson/Developer/Projects/velicour/.dart_tool/package_config.json -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts
--track-widget-creation --filesystem-scheme org-dartlang-root --initialize-from-dill build/cache.dill.track.dill --flutter-widget-cache
--enable-experiment=alternative-invalidation-strategy
[  +45 ms] <- compile package:velicour/main.dart
[+1615 ms] Activating Dart DevTools...
[+3343 ms] Activating Dart DevTools... (completed in 3.3s)
[+2920 ms] Updating files.
[   +7 ms] DevFS: Sync finished
[   +3 ms] Syncing files to device macOS... (completed in 7.9s)
[   +2 ms] Synced 0.0MB.
[   +4 ms] <- accept
[  +25 ms] Connected to _flutterView/0x7fe607100a20.
[  +18 ms] Flutter run key commands.
[  +13 ms] r Hot reload. 🔥🔥🔥
[   +3 ms] R Hot restart.
[        ] h List all available interactive commands.
[        ] d Detach (terminate "flutter run" but leave application running).
[        ] c Clear the screen
[   +4 ms] q Quit (terminate the application on the device).
[        ] 💪 Running with sound null safety 💪
[   +1 ms] An Observatory debugger and profiler on macOS is available at: http://127.0.0.1:50468/7EpInU_Pc7Q=/
[   +5 ms] The Flutter DevTools debugger and profiler on macOS is available at: http://127.0.0.1:9100?uri=http://127.0.0.1:50468/7EpInU_Pc7Q=/

@knopp
Copy link
Contributor

knopp commented Sep 4, 2021

The logs looks good. You can capture logs from dart-code as well (Dart: Capture Debugging Logs in vscode) - do they show anything different?

@wilsonowilson
Copy link
Author

wilsonowilson commented Sep 4, 2021

Before "connecting to service protocol", it shows this:

[ +199 ms] Attempting to forward device port 50445 to host port 50695
[   +1 ms] executing: /Users/wilson/Developer/SDK/flutter/bin/cache/artifacts/usbmuxd/iproxy 50695:50445 --udid 00008020-001934582144002E --debug
[+1028 ms] Forwarded port ForwardedPort HOST:50695 to DEVICE:50445

The original port shown in the url is 50445, but Dart code is forwarding 50695 to it

@knopp
Copy link
Contributor

knopp commented Sep 4, 2021

iproxy shouldn't be involved. That's when you're debugging on a device. Is the selected device in vscode (status bar option) macOS?

@wilsonowilson
Copy link
Author

Ah, that was the problem. The device changed automatically when I plugged in a new one. Setting it back to macOS fixed it. Thanks for the help!

@knopp
Copy link
Contributor

knopp commented Sep 4, 2021

It should be possible to set deviceId in launch.json. You can try adding "deviceId": "macos", for osx to see if it helps. It should override the setting.

@wilsonowilson
Copy link
Author

Overriding the deviceId works great. Thanks!

@knopp
Copy link
Contributor

knopp commented Sep 4, 2021

I think I should update the template launch.json :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants