Skip to content

Cannot connect to vm service on real device when the Flutter update to 2.x #84069

@talisk

Description

@talisk

Steps to Reproduce

IMPORTANT Make sure your flutter version is 2.x, I reproduced the problem on 2.0.1 stable and 2.2.1 stable. But everything works fine on the old version like 1.22.3 stable. AND everything works fine on the simulator.

Demo

  1. Clone my demo project
  2. flutter pub get
  3. flutter run: Run the demo on iPhone real device, Android real device and simulator.
  4. Press the button in the demo, check debug output

Expected results: The connection on Flutter 2.x is normal like the Flutter 1.22.3.

Actual results:

iOS device Android device Simulator
Flutter 1.22.3
Flutter 2.0.1
Flutter 2.2.1

Details

iOS real device output (iPhone 7 Plus with iOS 12.4, iPhone 11 Pro with iOS 14.0):

[VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: SocketException: OS Error: Connection refused, errno = 61, address = 127.0.0.1, port = 63737

Android real device output (Samsung S10 with Android 11):

E/flutter (21242): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = 127.0.0.1, port = 57704

This is the core code:

ServiceProtocolInfo info = await Service.getInfo();
String url = info.serverUri.toString();
Uri uri = Uri.parse(url);
Uri socketUri = convertToWebSocketUrl(serviceProtocolUrl: uri);
final isolateId = Service.getIsolateID(Isolate.current);
final service = await vmServiceConnectUri(socketUri.toString());

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: regressionIt was better in the past than it is nowdependency: dartDart team may need to help usfound in release: 2.2Found to occur in 2.2has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions