Skip to content

Commit 6e7cc56

Browse files
Handle unexpected exceptions during Azure metadata detection (flutter#189457)
<!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> ## Description Azure metadata detection is a best-effort environment check and should never prevent the Flutter CLI from starting. In some network environments (for example, transparent proxies or enterprise firewalls), requests to the Azure metadata endpoint (`http://169.254.169.254/metadata/instance`) may result in unexpected exceptions instead of the currently expected network-related exceptions. These exceptions currently propagate and terminate the Flutter CLI. This change catches unexpected exceptions during Azure metadata detection and treats them as "not running on Azure", which is consistent with the behavior for other metadata lookup failures. A regression test has been added to verify this behavior. ## Issues flutter#189456 ## Pre-launch Checklist - [ X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ X] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [ 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]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **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 [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [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 --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 2dc2727 commit 6e7cc56

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

‎packages/flutter_tools/lib/src/base/bot_detector.dart‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,17 @@ class AzureDetector {
107107
.timeout(requestTimeout);
108108
request.headers.add('Metadata', true);
109109
await request.close();
110-
} on SocketException {
111-
// If there is an error on the socket, it probably means that we are not
112-
// running on Azure.
113-
return _isRunningOnAzure = false;
114110
} on HttpException {
115-
// If the connection gets set up, but encounters an error condition, it
116-
// still means we're on Azure.
111+
// The connection was established but an HTTP error occurred.
112+
// This still indicates we're running on Azure.
117113
return _isRunningOnAzure = true;
118-
} on TimeoutException {
119-
// The HttpClient connected to a host, but it did not respond in a timely
120-
// fashion. Assume we are not on a bot.
121-
return _isRunningOnAzure = false;
122-
} on OSError {
123-
// The HttpClient might be running in a WSL1 environment.
114+
} on Object {
115+
// Metadata detection is best-effort. Any other failure (socket errors,
116+
// timeouts, malformed redirect URIs, WSL1 networking issues, etc.)
117+
// should not prevent Flutter from starting.
124118
return _isRunningOnAzure = false;
125119
}
120+
126121
// We got a response. We're running on Azure.
127122
return _isRunningOnAzure = true;
128123
}

‎packages/flutter_tools/test/general.shard/base/bot_detector_test.dart‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,5 +182,19 @@ void main() {
182182

183183
expect(await azureDetector.isRunningOnAzure, isTrue);
184184
});
185+
testWithoutContext('isRunningOnAzure returns false when an unexpected exception is thrown', () async {
186+
final azureDetector = AzureDetector(
187+
httpClientFactory: () => FakeHttpClient.list(<FakeRequest>[
188+
FakeRequest(
189+
azureUrl,
190+
responseError: ArgumentError(
191+
'No host specified in URI http:///e2gerror.php',
192+
),
193+
),
194+
]),
195+
);
196+
expect(await azureDetector.isRunningOnAzure, isFalse);
197+
});
185198
});
199+
186200
}

0 commit comments

Comments
 (0)