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

"flutter daemon" leaves orphaned "xcdevice observe" processes around after being terminated #73859

Open
DanTup opened this issue Jan 13, 2021 · 13 comments
Labels
found in release: 3.19 Found to occur in 3.19 found in release: 3.20 Found to occur in 3.20 has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list platform-ios iOS applications specifically platform-mac Building on or for macOS specifically t: xcode "xcodebuild" on iOS and general Xcode project management team-ios Owned by iOS platform team tool Affects the "flutter" command-line tool. See also t: labels. triaged-ios Triaged by iOS platform team

Comments

@DanTup
Copy link
Contributor

DanTup commented Jan 13, 2021

I can't repro this from the terminal (though that uses SIGINT on Ctrl+C and we generally), but from VS Code (which uses SIGTERM for all of its spawned processes) or the script below, the device daemon leaves behind some orphaned xcdevice proceses.

The script spawns the daemon, waits 10 seconds, then calls .kill(). After it completes, a /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --both process remains. If I open/close lots of projects in VS Code, they will build up.

I'm testing with the latest master branch.

import 'dart:convert';
import 'dart:io';

Future<void> main(List<String> arguments) async {
  print('Spawning...');
  final proc = await Process.start('flutter', ['daemon']);
  proc.stderr.transform(utf8.decoder).listen(print);
  proc.stdout.transform(utf8.decoder).listen(print);
  await Future.delayed(const Duration(seconds: 1));

  print('Enabling devices...');
  proc.stdin.writeln('[{"id":"2","method":"device.enable"}]');
  await Future.delayed(const Duration(seconds: 10));

  print('Terminating...');
  proc.kill();

  print('Done!');
}
@TahaTesser
Copy link
Member

Screenshot 2021-01-13 at 9 23 09 PM

flutter doctor -v
[✓] Flutter (Channel master, 1.26.0-2.0.pre.313, on macOS 11.1 20C69 darwin-x64, locale en-GB)
    • Flutter version 1.26.0-2.0.pre.313 at /Users/tahatesser/Code/flutter_master
    • Framework revision 1cb0a24a46 (10 hours ago), 2021-01-12 21:39:27 -0800
    • Engine revision 10cee6abcb
    • Dart version 2.12.0 (build 2.12.0-214.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Volumes/Extreme/SDK
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = /Volumes/Extreme/SDK
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Volumes/Extreme/Xcode.app/Contents/Developer
    • Xcode 12.3, Build version 12C33
    • CocoaPods version 1.10.1

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

[✓] Android Studio (version 4.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 1.8.0_242-release-1644-b3-6915495)

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

[✓] Connected device (4 available)
    • Taha’s iPad (mobile) • 00008020-000255113EE8402E            • ios            • iOS 14.3
    • iPhone 12 (mobile)   • 2FC46D8B-2A58-4ABB-B3FF-76F1AEC857FF • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)      • macos                                • darwin-x64     • macOS 11.1 20C69 darwin-x64
    • Chrome (web)         • chrome                               • web-javascript • Google Chrome 87.0.4280.141

• No issues found!

@TahaTesser TahaTesser added found in release: 1.26 Found to occur in 1.26 has reproducible steps The issue has been confirmed reproducible and is ready to work on tool Affects the "flutter" command-line tool. See also t: labels. platform-mac Building on or for macOS specifically t: xcode "xcodebuild" on iOS and general Xcode project management labels Jan 13, 2021
@osaxma
Copy link
Contributor

osaxma commented Feb 24, 2021

This gets messy sometimes, especially when switching between projects quite often.

I'm using the latest master 1.27.0-5.0.pre.102.

image

@Luckey-Elijah
Copy link

Luckey-Elijah commented Mar 4, 2021

I also am seeing the same behavior on Flutter 2.0.0 still 😞:

$ ps
PID TTY           TIME CMD
4058 ttys000    0:00.72 -zsh
6684 ttys001    0:00.09 /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --both
...
$ flutter --version
Flutter 2.0.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 60bd88df91 (21 hours ago) • 2021-03-03 09:13:17 -0800
Engine • revision 40441def69
Tools • Dart 2.12.0

@raulmabe
Copy link

raulmabe commented Apr 7, 2021

Same here!

✗ ps
  PID TTY           TIME CMD
28918 ttys000    0:00.37 /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --both
  894 ttys001    0:00.43 /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --both
 3580 ttys002    0:00.43 /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --both
57240 ttys003    0:00.38 /bin/zsh -l
57437 ttys004    0:00.27 /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --both
68599 ttys005    0:00.25 /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --both
89164 ttys006    0:00.17 /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --both

flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, 2.1.0-12.2.pre, on macOS 11.1 20C69 darwin-x64, locale es-ES)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.55.0)
[✓] Connected device (2 available)

@jmagman jmagman added this to Awaiting triage in Tools - Xcode review via automation Jun 8, 2021
@jonahwilliams jonahwilliams added the P2 Important issues not at the top of the work list label Jun 8, 2021
@jmagman jmagman added this to To do in iOS Developer Experience via automation Sep 28, 2021
@jmagman jmagman added the platform-ios iOS applications specifically label Sep 28, 2021
@anzbert
Copy link

anzbert commented Feb 8, 2022

still happening on flutter 2.10

@iDestin
Copy link

iDestin commented Nov 5, 2022

I have the same problem, Does anyone have a solution? lol..........😑

@osaxma
Copy link
Contributor

osaxma commented Nov 5, 2022

I use this command to remove them every once in a while....

kill -9 $(ps aux | grep -w "/Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe" | grep -v "grep" | awk '{print $2}')

Not ideal but at least it cleans the mess..

@flutter-triage-bot flutter-triage-bot bot added multiteam-retriage-candidate team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team labels Jul 8, 2023
@osaxma
Copy link
Contributor

osaxma commented Sep 11, 2023

Now Flutter leaves two orphaned processes instead of one per VS Code instance.

Here is an example after opening a flutter project 3 times:

 1670 ttys006    0:00.14 /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --usb
 1672 ttys009    0:00.14 /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --wifi

 1918 ttys005    0:00.13 /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --usb
 1920 ttys007    0:00.13 /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --wifi

 2214 ttys008    0:00.13 /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --usb
 2216 ttys010    0:00.13 /Applications/Xcode.app/Contents/Developer/usr/bin/xcdevice observe --wifi

using: Flutter (Channel stable, 3.13.0, on macOS 12.6 21G115 darwin-x64, locale en)

@StefanReinDexcom
Copy link

This is why I got this message starting the Simulator:

Unable to boot device due to insufficient system resources.
Please see Simulator Help for information on adjusting resource limits.

pkill -f xcdevice

This reduced the number of 1000 processes from 1380 down to 393 for me and I was able to start the simulator again without a restart.

@osaxma
Copy link
Contributor

osaxma commented Dec 13, 2023

FYI, this issue no longer happen for me with the following setup:

  • VS Code version: 1.85.0
  • Flutter version: 3.16.0 (stable) on macOS 12.7 21G816 darwin-x64

When I close VS code of a Flutter project, no child processes are left behind.

@StefanReinDexcom
Copy link

On my other notebook I also don't have this problem.
I think all my versions (Flutter, OS etc.) is newer there.

@DanTup
Copy link
Contributor Author

DanTup commented Dec 13, 2023

The issue still seems to occur using my script from the original post:

Screenshot 2023-12-13 at 10 39 08

Perhaps the cleanup is better from VS Code (because we try to send a graceful close command), but I think it's still a bug that it doesn't happen automatically if the process is just killed.

@danagbemava-nc
Copy link
Member

Reproducible using the script provided in #73859 (comment)

37025 ??         0:00.00 /usr/bin/script -t 0 /dev/null /usr/bin/arch -arm64e xcrun xcdevice observe --usb
37027 ??         0:00.00 /usr/bin/script -t 0 /dev/null /usr/bin/arch -arm64e xcrun xcdevice observe --wifi
58564 ttys000    0:00.00 grep xcdevice
37026 ttys004    0:02.58 /Applications/Xcode-15.2.0.app/Contents/Developer/usr/bin/xcdevice observe --usb
37028 ttys005    0:02.62 /Applications/Xcode-15.2.0.app/Contents/Developer/usr/bin/xcdevice observe --wifi
flutter doctor -v
[!] Flutter (Channel stable, 3.19.0, on macOS 14.3.1 23D60 darwin-arm64, locale en-GB)
    • Flutter version 3.19.0 on channel stable at /Users/nexus/dev/sdks/flutter
    ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutters/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutter. Consider adding /Users/nexus/dev/sdks/flutter/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutters/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutter. Consider adding /Users/nexus/dev/sdks/flutter/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision bae5e49bc2 (2 days ago), 2024-02-13 17:46:18 -0800
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode-15.2.0.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.14.3

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

[✓] Android Studio (version 2023.1)
    • Android Studio at /Users/nexus/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.7+0-17.0.7b1000.6-10550314)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
    • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 77.2.2
    • Dart plugin version 232.10286

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

[✓] Connected device (4 available)
    • Dean’s iPad (mobile) • 00008103-000825C811E3401E • ios            • iOS 17.3 21D50
    • Nexus (mobile)       • 00008020-001875E83A38002E • ios            • iOS 17.3.1 21D61
    • macOS (desktop)      • macos                     • darwin-arm64   • macOS 14.3.1 23D60 darwin-arm64
    • Chrome (web)         • chrome                    • web-javascript • Google Chrome 121.0.6167.184

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

! Doctor found issues in 1 category.
[✓] Flutter (Channel master, 3.20.0-7.0.pre.83, on macOS 14.3.1 23D60 darwin-arm64, locale en-GB)
    • Flutter version 3.20.0-7.0.pre.83 on channel master at /Users/nexus/dev/sdks/flutters
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 6ee7e24bfe (6 hours ago), 2024-02-16 00:51:06 -0500
    • Engine revision dd530f1556
    • Dart version 3.4.0 (build 3.4.0-148.0.dev)
    • DevTools version 2.33.0-dev.6

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode-15.2.0.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.14.3

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

[✓] Android Studio (version 2023.1)
    • Android Studio at /Users/nexus/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.7+0-17.0.7b1000.6-10550314)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
    • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 77.2.2
    • Dart plugin version 232.10286

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

[✓] Connected device (5 available)
    • Dean’s iPad (mobile)            • 00008103-000825C811E3401E • ios            • iOS 17.3 21D50
    • Nexus (mobile)                  • 00008020-001875E83A38002E • ios            • iOS 17.3.1 21D61
    • macOS (desktop)                 • macos                     • darwin-arm64   • macOS 14.3.1 23D60 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad     • darwin         • macOS 14.3.1 23D60 darwin-arm64
    • Chrome (web)                    • chrome                    • web-javascript • Google Chrome 121.0.6167.184

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

• No issues found!

@danagbemava-nc danagbemava-nc added found in release: 3.19 Found to occur in 3.19 found in release: 3.20 Found to occur in 3.20 and removed found in release: 1.26 Found to occur in 1.26 labels Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
found in release: 3.19 Found to occur in 3.19 found in release: 3.20 Found to occur in 3.20 has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list platform-ios iOS applications specifically platform-mac Building on or for macOS specifically t: xcode "xcodebuild" on iOS and general Xcode project management team-ios Owned by iOS platform team tool Affects the "flutter" command-line tool. See also t: labels. triaged-ios Triaged by iOS platform team
Projects
Tools - Xcode review
  
Awaiting triage
Development

No branches or pull requests