Skip to content

Migrate HTTP retry GET for SDK version utils. #8722

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

Merged
merged 1 commit into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions pkg/_pub_shared/lib/utils/dart_sdk_version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,19 @@ final _logger = Logger('tool.sdk_version');
Future<CachedSdkVersion?> fetchLatestDartSdkVersion({
required String channel,
}) async {
for (var i = 0; i < 3; i++) {
final client = httpRetryClient();
try {
final rs = await client.get(Uri.parse(
'https://storage.googleapis.com/dart-archive/channels/$channel/release/latest/VERSION'));
if (rs.statusCode != 200) {
_logger.warning(
'Unable to fetch the Dart SDK version, status code: ${rs.statusCode}');
continue;
}
final map = json.decode(rs.body) as Map<String, dynamic>;
final version = map['version'] as String;
final date = DateTime.parse(map['date'] as String);
return CachedSdkVersion(version, date);
} catch (e, st) {
_logger.warning('Unable to fetch the Dart SDK version', e, st);
continue;
} finally {
client.close();
}
try {
return await httpGetWithRetry(
Uri.parse(
'https://storage.googleapis.com/dart-archive/channels/$channel/release/latest/VERSION'),
responseFn: (rs) {
final map = json.decode(rs.body) as Map<String, dynamic>;
final version = map['version'] as String;
final date = DateTime.parse(map['date'] as String);
return CachedSdkVersion(version, date);
},
);
} catch (e, st) {
_logger.warning('Unable to fetch the Dart SDK version', e, st);
}
return null;
}
22 changes: 9 additions & 13 deletions pkg/_pub_shared/lib/utils/flutter_archive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@ final _logger = Logger('flutter_archive');
///
/// Returns `null` if the archive cannot be fetched.
Future<FlutterArchive?> fetchFlutterArchive() async {
for (var i = 0; i < 3; i++) {
final client = httpRetryClient();
try {
final rs = await client.get(Uri.parse(
'https://storage.googleapis.com/flutter_infra_release/releases/releases_linux.json'));
return FlutterArchive.fromJson(
json.decode(rs.body) as Map<String, Object?>);
} catch (e, st) {
_logger.warning('Unable to fetch the Flutter SDK archive', e, st);
continue;
} finally {
client.close();
}
try {
return await httpGetWithRetry(
Uri.parse(
'https://storage.googleapis.com/flutter_infra_release/releases/releases_linux.json'),
responseFn: (rs) =>
FlutterArchive.fromJson(json.decode(rs.body) as Map<String, Object?>),
);
} catch (e, st) {
_logger.warning('Unable to fetch the Flutter SDK archive', e, st);
}
return null;
}
Expand Down