-
Notifications
You must be signed in to change notification settings - Fork 29.7k
[beta] Show error on macOS if missing Local Network permissions #162119
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
[beta] Show error on macOS if missing Local Network permissions #162119
Conversation
) ### Background macOS Sequoia requires the user's permission to do multicast operations, which the Flutter tool does to connect to the Dart VM. If the app does not have permission to communicate with devices on the local network, the following happens: 1. Flutter tool starts a [multicast lookup](https://github.com/flutter/flutter/blob/bb2d34126cc8161dbe4a1bf23c925e48b732f670/packages/flutter_tools/lib/src/mdns_discovery.dart#L238-L241) 2. The mDNS client [sends data on the socket](https://github.com/flutter/packages/blob/973e8b59e24ba80d3c36a2bcfa914fcfd5e19943/packages/multicast_dns/lib/multicast_dns.dart#L219) 4. macOS blocks the operation. Dart's native socket implementation throws an `OSError` 5. Dart's `Socket.send` [catches the `OSError`](https://github.com/dart-lang/sdk/blob/da6dc03a15822d83d9180bd766c02d11aacdc06b/sdk/lib/_internal/vm/bin/socket_patch.dart#L1511-L1515), wraps it in a `SocketException`, and [schedules a microtask](https://github.com/dart-lang/sdk/blob/da6dc03a15822d83d9180bd766c02d11aacdc06b/sdk/lib/_internal/vm/bin/socket_patch.dart#L1513) that [reports the exception through the socket's stream](https://github.com/dart-lang/sdk/blob/95f00522676dff03f64fc715cb1835ad451faa4c/sdk/lib/_internal/vm/bin/socket_patch.dart#L3011) ([`Socket` is a `Stream`](https://api.dart.dev/dart-io/Socket-class.html)) 6. The mDNS client [does not listen to the socket stream's errors](https://github.com/flutter/packages/blob/973e8b59e24ba80d3c36a2bcfa914fcfd5e19943/packages/multicast_dns/lib/multicast_dns.dart#L155), so [the error is sent to the current `Zone`'s uncaught error handler](https://github.com/dart-lang/sdk/blob/95f00522676dff03f64fc715cb1835ad451faa4c/sdk/lib/async/stream_impl.dart#L553). ### Reproduction To reproduce this error on macOS... 1. Open System Settings > Privacy & Security > Local Network and toggle off Visual Studio Code 2. Run a Flutter app using a physical device ### Fix Ideally, we'd make `MDnsClient.lookup` throw an exception for this scenario. Unfortunately, the `MDnsClient` can have multiple lookup operations in parallel, and the `SocketException` doesn't give us enough information to match it back to a pending `MDnsClient` request. See flutter/packages#8450 as an attempt to solve this in the `MDnsClient` layer. Instead, this fix introduces a `Zone` in the tool to catch the socket's uncaught exception. Follow-up to flutter#157638 See: flutter#150131 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- 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
|
@loic-sharma this is for the beta branch with intention to land in the next stable build released. I have updated the title to keep the release engineer aware. As this is a change to the beta branch, it does not require a changelog update. |
|
Ah thanks for the correction! |
bkonyi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. This is the top crasher for the Flutter tool and this fix would be great to get cherry picked.
|
The beta release is currently building, so this will have to go into the next one. |
|
@justinmc Do I need to change the target branch to get in the next beta? |
|
I think no, it will be the same branch |
|
autosubmit label was removed for flutter/flutter/162119, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
There are test failures here: Although the failure makes me suspicious that these are not hermetic tests. cc @bkonyi |
This was resolved in #161917 |
Thanks, I'll patch this in to the branch |
This test was merging two ZeroExecutionTimeValidationResults into a new ValidationResult with an actual execution duration set rather than Duration.zero. Fixes flutter#161918
|
I just pushed a CP of: 3bfc25f |
bd28ab6
into
flutter:flutter-3.29-candidate.0
…ter#162119)⚠️ This targets branch `flutter-3.29-candidate.0` for the Flutter beta. Cherrypicks flutter#161846 to `flutter-3.29-candidate.0`. **Impacted Users**: Users that use macOS Sequoia and haven't turned on Local Network permissions for their IDE or terminal app. See: flutter#150131 **Impact Description**: Without this improved error message, `flutter run` outputs this error: `SocketException: Send failed, OS Error: No route to host, errno = 65`. **Workaround**: Turn on Local Network permissions for your IDE or terminal app. However, it's difficult for customers to discover this from the error message. **Risk**: This change could regress the tool's Dart VM discovery. **Test Coverage**: Yes added tests **Validation Steps**: In System Settings > Privacy & Security > Local Network, toggle off Visual Studio Code. In VS Code, run a Flutter app on a physical device.
flutter-3.29-candidate.0for the Flutter beta.Cherrypicks #161846 to
flutter-3.29-candidate.0.Impacted Users: Users that use macOS Sequoia and haven't turned on Local Network permissions for their IDE or terminal app. See: #150131
Impact Description: Without this improved error message,
flutter runoutputs this error:SocketException: Send failed, OS Error: No route to host, errno = 65.Workaround: Turn on Local Network permissions for your IDE or terminal app. However, it's difficult for customers to discover this from the error message.
Risk: This change could regress the tool's Dart VM discovery.
Test Coverage: Yes added tests
Validation Steps: In System Settings > Privacy & Security > Local Network, toggle off Visual Studio Code. In VS Code, run a Flutter app on a physical device.