Skip to content

[flutter_tools] Fix macOS flutter attach VM service discovery#183253

Closed
mayanksharma9 wants to merge 2 commits into
flutter:masterfrom
mayanksharma9:fix/issue-183248
Closed

[flutter_tools] Fix macOS flutter attach VM service discovery#183253
mayanksharma9 wants to merge 2 commits into
flutter:masterfrom
mayanksharma9:fix/issue-183248

Conversation

@mayanksharma9

@mayanksharma9 mayanksharma9 commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

This updates macOS flutter attach VM service discovery to use both mDNS and log scanning.

Before this change, macOS attach relied on log-based VM service discovery on the macOS path. In cases where that path did not surface the VM service URI reliably, attach could miss it and time out.

This change matches the iOS simulator/device attach strategy by delegating to:

  • mDNS discovery
  • existing log-scanning discovery as fallback

Fixes #183248

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

Tests

  • ../../bin/cache/dart-sdk/bin/dart analyze lib/src/macos/macos_device.dart test/general.shard/macos/macos_device_test.dart
  • ../../bin/cache/dart-sdk/bin/dart test test/general.shard/macos/macos_device_test.dart

@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. a: desktop Running on desktop team-ios Owned by iOS platform team team-macos Owned by the macOS platform team platform-macos labels Mar 4, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates flutter attach on macOS to use both mDNS and log scanning for VM service discovery. It introduces an override for getVMServiceDiscoveryForAttach in MacOSDevice that delegates to both MdnsVMServiceDiscoveryForAttach and the existing LogScanningVMServiceDiscoveryForAttach. A corresponding test has been added to verify this behavior. My review found one opportunity for improvement regarding documentation.

return flutterProject.macos.existsSync();
}

@override

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This new public method override is missing a documentation comment. The style guide requires all public members to be documented. Please add a /// doc comment explaining that this implementation uses both mDNS and log scanning for VM service discovery.

  /// Returns a [VMServiceDiscoveryForAttach] that uses both mDNS and log scanning.
  @override
References
  1. All public members should have documentation. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the doc comment in 29ca58f.

@mayanksharma9

Copy link
Copy Markdown
Contributor Author

Addressed — added a doc comment on explaining it uses both mDNS and log scanning.\n\nCommit: 29ca58f

@mayanksharma9

Copy link
Copy Markdown
Contributor Author

Follow-up: added the requested method doc comment in commit 29ca58f.

@bkonyi bkonyi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from a tool's perspective. Will let @vashworth sign off as the platform TL.

@hellohuanlin

Copy link
Copy Markdown
Contributor

I'm a bit confused with how this PR fixes the linked issue:

Before this change, macOS attach only scanned the local tool log stream. When an app was started from a different terminal, attach could miss the VM service URI and time out.

I'm surprised that the logging based VM service discovery only checks the terminal. Looking at the code, it seems to check the device log, so it shouldn't matter which terminal runs flutter run? @vashworth would know more.

@mayanksharma9

Copy link
Copy Markdown
Contributor Author

@hellohuanlin Thanks for calling that out. You are right to question the wording there. The issue is not about the app being started from a different terminal by itself. The real problem is that the current macOS attach path can miss the VM service URI when log based discovery does not surface it reliably, and this change makes attach use mDNS as well instead of depending only on that path. I will tighten up the PR description so it matches the actual failure mode more accurately.

@stuartmorgan-g

Copy link
Copy Markdown
Contributor

Note to reviewers: this user appears to be running an unsupervised or poorly-supervised agent, and has received a warning and temporary ban. If interaction resumes next week, approach the review with caution.

@hellohuanlin

Copy link
Copy Markdown
Contributor

From triage: we have decided not to proceed with this PR given the past interaction.

github-merge-queue Bot pushed a commit that referenced this pull request Mar 26, 2026
#182972 (comment)
attempted to add mac-reviewers to flutter_tool PRs in addition to
ios-reviewers, but it didn't apply both:
#183253

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
ahmedsameha1 pushed a commit to ahmedsameha1/flutter that referenced this pull request Apr 14, 2026
flutter#182972 (comment)
attempted to add mac-reviewers to flutter_tool PRs in addition to
ios-reviewers, but it didn't apply both:
flutter#183253

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
@stuartmorgan-g stuartmorgan-g added platform-macos Building on or for macOS specifically and removed platform-macos labels Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop platform-macos Building on or for macOS specifically team-ios Owned by iOS platform team team-macos Owned by the macOS platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flutter attach fails to attach to macos app

4 participants