Skip to content

Explicit timeouts in check_domain_access.dart #5025

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
Aug 16, 2021
Merged
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
14 changes: 8 additions & 6 deletions app/bin/tools/check_domain_access.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Future<void> main(List<String> args) async {
print('Done.');
}

final timeLimit = Duration(seconds: 15);
final urls = <String>[
// package info
'https://pub.dev/api/packages/http',
Expand All @@ -42,12 +43,13 @@ Future<void> _checkHosts() async {
for (final type in [InternetAddressType.IPv4, InternetAddressType.IPv6]) {
final typeStr = type == InternetAddressType.IPv4 ? 'IPv4' : 'IPv6';
try {
final addresses = await InternetAddress.lookup(host, type: type);
final addresses =
await InternetAddress.lookup(host, type: type).timeout(timeLimit);
final failed = <InternetAddress>[];
for (final address in addresses) {
try {
final s = await Socket.connect(address, 443);
await s.close();
final s = await Socket.connect(address, 443).timeout(timeLimit);
await s.close().timeout(timeLimit);
} catch (_) {
failed.add(address);
}
Expand All @@ -71,9 +73,9 @@ Future<void> _checkUrls({HttpClient? client}) async {
Future<void> _checkUrlGetContent(Uri uri, {HttpClient? client}) async {
final closeClient = client == null;
client ??= HttpClient();
final rq = await client.getUrl(uri);
final rs = await rq.close();
final bodyList = await rs.toList();
final rq = await client.getUrl(uri).timeout(timeLimit);
final rs = await rq.close().timeout(timeLimit);
final bodyList = await rs.toList().timeout(timeLimit);
final bodyLength = bodyList.map((e) => e.length).reduce((a, b) => a + b);
if (bodyLength <= 0) throw Exception('No body for $uri');
if (rs.statusCode != 200) throw Exception('Failed to fetch $uri');
Expand Down