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

"Lost connection to device" randomly when not doing anything in particular #9707

Open
Hixie opened this issue May 1, 2017 · 64 comments
Open
Labels
customer: crowd Affects or could affect many people, though not necessarily a specific customer. P2 Important issues not at the top of the work list platform-android Android applications specifically team-android Owned by Android platform team tool Affects the "flutter" command-line tool. See also t: labels. triaged-android Triaged by Android platform team

Comments

@Hixie
Copy link
Contributor

Hixie commented May 1, 2017

We should keep closer track of what adb is doing. Is it dying on us? The logs don't say.

[+1366 ms] I/flutter (26953): <some stuff i was printing to the console>
[  +13 ms] I/flutter (26953): <ditto>
[   +1 ms] I/flutter (26953): <ditto>
[        ] I/flutter (26953): <ditto>
[        ] I/flutter (26953): <ditto>
[+128298 ms] Service protocol connection closed.
[        ] Lost connection to device.
[   +1 ms] DevFS: Deleting filesystem on the device (file:///data/user/0/io.flutter.examples.gallery/cache/flutter_galleryIgEdy5/flutter_gallery/)
[ +251 ms] TimeoutException after 0:00:00.250000: Future not completed
[        ] 'flutter run' took 561,659ms.
[  +32 ms] ensureAnalyticsSent: 31ms
[        ] exiting with code 0
@Hixie Hixie added the tool Affects the "flutter" command-line tool. See also t: labels. label May 1, 2017
@zoechi
Copy link
Contributor

zoechi commented Oct 9, 2017

I'm also wondering what I get a TimeoutException for

  +45 ms] D/        (20923): HostConnection::get() New Host Connection established 0x870ffc40, tid 20945
[  +60 ms] DevFS: Deleting filesystem on the device (file:///data/user/0/com.customer.project/cache/project_flutterNTBENX/project_flutter/)
[        ] _deleteDevFS: {fsName: project_flutter}
[   +4 ms] Service protocol connection closed.
[ +249 ms] TimeoutException after 0:00:00.250000: Future not completed
[        ] Application finished.
[{"id":0,"result":true}]
[{"event":"app.stop","params":{"appId":"f0e87c31-b8dc-4cdb-90cf-f5a8e24e1a58"}}]
[  +16 ms] "flutter run" took 18,225ms.

@johnkenedyong
Copy link

i happen to experience this, i suspect its with memory things. My app has 2 tab, 1 is to load text infinitely and its ok, another tab is to load a list of image from network and its also infinite. when i test on second tab, the image is loading fine and when i place it without doing anything the app will crash and it happens both in emulator and real phone, but it took longer for emulator to crash since the pc spec is good while the phone crash much faster.

There is no log, no nothing, the app just crash like that. Hope flutter can fix it

@prateekdubeydynamic
Copy link

This is happening even on the Get Started Demo when hot-reloading on a Samsung SM G900A device running Android 26 and there is no log, no notification, the app just snaps.

Thanks for your help..Go Flutter!

@JordyBaylac

This comment was marked as duplicate.

@choongyong
Copy link

I am facing the same issue. For me it happens on a page with a Stopwatch running while loading an animated GIF. Flutter crashes with similar log, on both simulator, and actual Android and iPhone devices.

Is there some clue from the line TimeoutException after 0:00:00.250000: Future not completed? Too coincidental that it is always 0.25 seconds from the few logs shared above.

[+104656 ms] Service protocol connection closed.
[   +1 ms] Lost connection to device.
[   +2 ms] DevFS: Deleting filesystem on the device (file:///data/user/0/com.cust.app/cache/custXMFXED/cust/)
[        ] _deleteDevFS: {fsName: cust}
[ +254 ms] TimeoutException after 0:00:00.250000: Future not completed
[  +12 ms] "flutter run" took 164,722ms.

@zoechi zoechi added the platform-android Android applications specifically label Feb 14, 2019
@zoechi zoechi added this to the Goals milestone Feb 14, 2019
@dhaval0122

This comment was marked as duplicate.

@ghost
Copy link

ghost commented Jun 11, 2019

I am also receiving the same issue randomly.

Im assuming it's a memory issue some how, my app in the Observatory says that I am using 445mb of memory which is INSANE. The only thing I am loading is a user's profile picture from Firebase Storage and I am using the Google Maps API to do nearby place searches.

@jeanchernandez
Copy link

jeanchernandez commented Jun 11, 2019

This problem is driving me crazy, as the app grows it becomes more and more impossible to debug, I have to try to run the app 5 times or more because it closes constantly, it has been like that since I started using flutter in February of this year and there are no signs that they know what causes it.

Definitely must be related to the amount of memory used, it happens more often when I'm using more applications in windows.

@sk3llo

This comment was marked as duplicate.

@ghost
Copy link

ghost commented Jun 15, 2019

@yethael @sk3llo Check out issue #32143. Looks like several others are also having this issue, it is for sure a RAM issue and it looks like Flutter has a couple developers working on this issue!

@jeanchernandez
Copy link

It seems more related to Android version, when I use a phone with Android 8.x the problem is really painful, but when I use an Android 6.x or 5.1 phone the problem disappears.

@DyaryRaoof

This comment was marked as duplicate.

@mertkokusen
Copy link

mertkokusen commented Jan 23, 2020

This problem is ruining development experience for me. I will not consider flutter for another project until this one gets solved, even thought I totally love the framework.

@shashikantshaale
Copy link

My app is crashing very often....
Don't know what is going wrong.

@aanalmehta-sa

This comment was marked as duplicate.

@TahaTesser TahaTesser added the customer: crowd Affects or could affect many people, though not necessarily a specific customer. label Mar 12, 2020
@oxydron
Copy link

oxydron commented Mar 13, 2020

Same problem. Trying to use lib multi_image_picker 4.6.3, which bugs my app when it tries to access storage to get images (this library works just fine on a sample simple project). I get the following message before the app just close:

Failed to send request: {"jsonrpc":"2.0","id":"1397","method":"resume","params":{"isolateId":"isolates/4275718744151023"}}

and

[+10514 ms] Service protocol connection closed.
[   +1 ms] Lost connection to device.
[   +2 ms] DevFS: Deleting filesystem on the device (file:///data/user/0/br.com.<my_company_name>.<secret_project_name>/code_cache/<secret_project_name>YGPRCR/<secret_project_name>/)
[        ] Sending to VM service: _deleteDevFS({fsName: <secret_project_name>})
[{"id":28,"result":true}]

@satishsoni777

This comment was marked as duplicate.

@Ludonope
Copy link

Same issue also after starting to use an image related library (gif_ani) so it's probably not specific to a library in particular.

@Ludonope
Copy link

I solved the issue for gif_ani, it was because of a listener on a completer which wasn't properly removed and kept being called. It might be a similar issue for https://github.com/Sh1d0w/multi_image_picker/issues/410 , I tried to look a little bit at the code of multi_image_picker but didn't immediately find a similar pattern.

It's still pretty weird that leaving a listener on it would end up crashing the application. At least it might be a lead.

@kf6gpe kf6gpe added the P2 Important issues not at the top of the work list label May 29, 2020
@kf6gpe kf6gpe removed this from the Goals milestone Jun 2, 2020
@Hixie Hixie removed this from the Goals milestone Jun 2, 2020
@Hixie Hixie removed this from the None. milestone Aug 17, 2020
@ingluife
Copy link

ingluife commented Aug 29, 2020

The same problem, I have a GridView to load multiple images. When I load many images on the list, the Flutter application is closed without throw any exception.

Has Someone fixed it?

Additional information:

  • I use the package: cached_network_image: ^2.3.1
  • Flutter log after closed:
[+15548 ms] Service protocol connection closed.
[   +2 ms] Lost connection to device.
[  +11 ms] executing: /Users/lgonzalez/Library/Android/sdk/platform-tools/adb -s d391d441 forward --list
[  +24 ms] Exit code 0 from: /Users/lgonzalez/Library/Android/sdk/platform-tools/adb -s d391d441 forward --list
[        ] d391d441 tcp:58719 tcp:35412
[   +4 ms] executing: /Users/lgonzalez/Library/Android/sdk/platform-tools/adb -s d391d441 forward --remove tcp:58719
[  +19 ms] DevFS: Deleting filesystem on the device (file:///data/user/0/app.criptolugares/code_cache/ubiappIXUJPE/ubiapp/)
[ +262 ms] Ignored error while cleaning up DevFS: TimeoutException after 0:00:00.250000: Future not completed
[   +3 ms] executing: /Users/lgonzalez/Library/Android/sdk/platform-tools/adb -s d391d441 forward --list
[  +12 ms] Exit code 0 from: /Users/lgonzalez/Library/Android/sdk/platform-tools/adb -s d391d441 forward --list
[   +3 ms] "flutter run" took 391,186ms.
[ +221 ms] ensureAnalyticsSent: 211ms
[   +2 ms] Running shutdown hooks
[        ] Shutdown hook priority 4
[  +25 ms] Shutdown hooks complete
[   +1 ms] exiting with code 0
  • Flutter doctor:
[✓] Flutter (Channel stable, 1.20.2, on Mac OS X 10.15.5 19F101, locale en-AR)
    • Flutter version 1.20.2 at /Users/lgonzalez/development/flutter-1.20.2
    • Framework revision bbfbf1770c (2 weeks ago), 2020-08-13 08:33:09 -0700
    • Engine revision 9d5b21729f
    • Dart version 2.9.1


[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/lgonzalez/Library/Android/sdk
    • Platform android-29, build-tools 29.0.2
    • ANDROID_HOME = /Users/lgonzalez/Library/Android/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-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3.1, Build version 11C504
    • CocoaPods version 1.9.1

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 48.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

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

[✓] Connected device (1 available)
    • SM J250M (mobile) • d391d441 • android-arm • Android 7.1.1 (API 25)

• No issues found!

@GustavoNeri02
Copy link

GustavoNeri02 commented Oct 26, 2023

✓  Built build/app/outputs/flutter-apk/app-debug.apk.
D/FlutterArchivePlugin(10350): onAttachedToEngine - IN
D/FlutterArchivePlugin(10350): doOnAttachedToEngine - IN
D/FlutterArchivePlugin(10350): doOnAttachedToEngine - OUT
D/FlutterArchivePlugin(10350): onAttachedToEngine - OUT
Connecting to VM Service at ws://127.0.0.1:49813/bkpQuTS7dZA=/ws
  Lost connection to device.
Exited

Updated: I solved the problem by switching the default USB mode to "PTP over USB" and disabling system logging in the android developers menu Since then none 'Lost connection' happened

Switch to "File Transfer" from "No data transfer" solves the problem I was having here

@andynewman10
Copy link

andynewman10 commented Oct 26, 2023

@GustavoNeri02 there are multiple causes for this error. One possible cause is the File Transfer that has not been enabled, and that indeed does need to be enabled for debug sessions to run smoothly. You're right.

But there seems to be other causes as well, and situations that are considerably more tricky to investigate.

In my case, a heap overflow somewhere in a background isolate could explain the behavior. I'm not even sure if "Break on: Uncaught exceptions" would help here.

I believe the Flutter team should be a little bit cautious about this, as there are a number of very annoying, recurrent (I mean very recurrent) issues when it comes to debug Flutter applications that could be addressed somehow. Considered the excellent work being done generally speaking so far, the spirit here is would be to provide the developer the maximum amount of assistance.

Anyway, just my $0.02.

@richard457
Copy link

richard457 commented Dec 9, 2023

I have been building in debug and it was working well until I released windows the app and run the app on another machine and the app suddenly stopped and closed without sending any stack trace.

@incrediblezayed

This comment was marked as duplicate.

@stukdev

This comment was marked as duplicate.

@ahmeedev
Copy link

Same issue when i try to use firebase on windows 10, but working on windows 11

@Galaf

This comment was marked as spam.

@Minhalatgit

This comment was marked as duplicate.

@Galaf
Copy link

Galaf commented Jun 8, 2024

Although not very straightforward, the problem disappeared on my side.
I can think of two culprits:

  1. The connection port. It chooses a random port at startup and I'm wondering if it might not have chosen a port already used by all those docker-compose images I had.

  2. Not straightforward problem in the code.
    Which I think is the real culprit.
    I did something such as:

onPressed: executeFunction()

Which seems to compile without any problem except it should actually be:

onPressed: executeFunction

And once I did that, the problem stopped happening.
Why Flutter doesn't print a big bad stack trace of exception is a mystery to me but I suggest you guys have a look at your code and see if you don't have any similar syntax issue.

Hope this helps.

@dx314
Copy link

dx314 commented Jun 9, 2024

This is happening to me with a fresh untouched flutter create new-project.

@icecandy
Copy link

Happenning to me with a connected iPhone 12 Pro device. All the time! ie randomly gives up the connection after a few minutes.

@Michal-MK
Copy link
Contributor

Here is my flutter run -v on an Android device Flutter 3.19.2

[        ] Performing hot restart...
[   +4 ms] Scanned through 630 files in 4ms
[        ] Syncing files to device LM G810...
[   +1 ms] <- reset
[        ] Compiling dart to kernel with 0 updated files
[        ] Processing bundle.
[        ] <- recompile package:layouts/main.dart 82f94efb-1e11-4383-9aa7-5658b86df08c
[        ] <- 82f94efb-1e11-4383-9aa7-5658b86df08c
[        ] Bundle processing done.
[  +28 ms] Updating files.
[ +397 ms] Service protocol connection closed.
[        ] Lost connection to device.
[        ] DevFS: Deleting filesystem on the device (file:///data/user/0/com.example.layouts/code_cache/layoutsCLBDVZ/layouts/)
ERROR - 2024-06-24 23:18:59.747201
PUT /EZja7KpuUIo=/
Error thrown by handler.
Connection closed before full header was received
package:shelf/shelf_io.dart 138:16  handleRequest

[  +15 ms] DevFS: Sync finished
[        ] Syncing files to device LM G810... (completed in 444ms)
[        ] Synced 35.3MB.
[        ] <- accept
[ +238 ms] Ignored error while cleaning up DevFS: TimeoutException after 0:00:00.250000: Future not completed

[   +4 ms] "flutter run" took 42,837ms.
[ +103 ms] ensureAnalyticsSent: 65ms
[        ] Running 1 shutdown hook
[   +1 ms] Shutdown hooks complete
[   +1 ms] exiting with code 0
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.2, on macOS 14.3 23D56 darwin-arm64, locale en-CZ)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio (version 2023.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.3)
[✓] VS Code (version 1.90.2)
[✓] Connected device (3 available)
    ! Error: Browsing on the local area network for iPad 9th generation. 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

@hangoocn
Copy link

hangoocn commented Jun 26, 2024

I am facing this issue on windows platform, so both and target platform is windows.
I am working with aws amplify and seems adding the storage plugin will have this issue in my app. But it actuallys works in a fresh new project with amplify storage, so very confusing behavior.

@favazHF

This comment was marked as spam.

@pavanpodila
Copy link

Daily annoyance right now ... hope we find a stable way to manage the connection

@andynewman10
Copy link

I remember seeing somewhere in the 3.24.x release notes that the 'Lost connection to device' message had been improved, in that it would provide an explanation as to why it occurred.

@pavanpodila
Copy link

pavanpodila commented Oct 2, 2024

I searched for it in https://docs.flutter.dev/release/release-notes/release-notes-3.24.0.

It's in the changelog instead: https://github.com/flutter/flutter/blob/master/CHANGELOG.md. Although from my daily experience I don't see any particular reason being printed on console.

@andynewman10
Copy link

@pavanpodila that's right, it is here, too, in the 3.24.2 release changelog:

https://github.com/flutter/flutter/blob/main/CHANGELOG.md#3242

states "When running a Flutter app, display a concise error message when connection to the device is lost" (#153769). I expected this enhancement would help us diagnose 'Lost connection to device' issues, but I too do not see any information when that happens.

@martipello

This comment was marked as spam.

@andyngdz

This comment was marked as duplicate.

@yees7
Copy link

yees7 commented Nov 2, 2024

I'm working on a project with v3.24.3 using camera and Google MLKit text recognition on Android, with a real android phone connected. Loses connection without any specific errors after ~5 minutes. It's too hard to work on the project anymore.

@andynewman10
Copy link

I am still having issues too, rarely though.

To be on the safe side, I usually set up wireless debugging for my phone using adb. This way, I make sure the problem does not come from my USB cable. I would suggest anybody subscribed to this thread to use wireless debugging.

@raphaelpinel
Copy link

Most of the time when I'm working I have both vscode and android studio open.

I just realized that if i close android studio i don't have the issue launching from vscode anymore.

Closing Android Studio worked for me

@agilst
Copy link

agilst commented Mar 13, 2025

Most of the time when I'm working I have both vscode and android studio open.
I just realized that if i close android studio i don't have the issue launching from vscode anymore.

Closing Android Studio worked for me

Image

I have only VSCode running on my Mac, no Android Studio, running on Flutter 3.24.1, connection is using cable to my Samsung phone. this happens everytime I switched to another app. I'd say debugging on Android device is inconvenient as this is happening frequently in my case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer: crowd Affects or could affect many people, though not necessarily a specific customer. P2 Important issues not at the top of the work list platform-android Android applications specifically team-android Owned by Android platform team tool Affects the "flutter" command-line tool. See also t: labels. triaged-android Triaged by Android platform team
Projects
None yet
Development

No branches or pull requests