Skip to content

Commit 2142361

Browse files
authored
Explicit timeouts in check_domain_access.dart (#5025)
1 parent 67b835d commit 2142361

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

app/bin/tools/check_domain_access.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Future<void> main(List<String> args) async {
2525
print('Done.');
2626
}
2727

28+
final timeLimit = Duration(seconds: 15);
2829
final urls = <String>[
2930
// package info
3031
'https://pub.dev/api/packages/http',
@@ -42,12 +43,13 @@ Future<void> _checkHosts() async {
4243
for (final type in [InternetAddressType.IPv4, InternetAddressType.IPv6]) {
4344
final typeStr = type == InternetAddressType.IPv4 ? 'IPv4' : 'IPv6';
4445
try {
45-
final addresses = await InternetAddress.lookup(host, type: type);
46+
final addresses =
47+
await InternetAddress.lookup(host, type: type).timeout(timeLimit);
4648
final failed = <InternetAddress>[];
4749
for (final address in addresses) {
4850
try {
49-
final s = await Socket.connect(address, 443);
50-
await s.close();
51+
final s = await Socket.connect(address, 443).timeout(timeLimit);
52+
await s.close().timeout(timeLimit);
5153
} catch (_) {
5254
failed.add(address);
5355
}
@@ -71,9 +73,9 @@ Future<void> _checkUrls({HttpClient? client}) async {
7173
Future<void> _checkUrlGetContent(Uri uri, {HttpClient? client}) async {
7274
final closeClient = client == null;
7375
client ??= HttpClient();
74-
final rq = await client.getUrl(uri);
75-
final rs = await rq.close();
76-
final bodyList = await rs.toList();
76+
final rq = await client.getUrl(uri).timeout(timeLimit);
77+
final rs = await rq.close().timeout(timeLimit);
78+
final bodyList = await rs.toList().timeout(timeLimit);
7779
final bodyLength = bodyList.map((e) => e.length).reduce((a, b) => a + b);
7880
if (bodyLength <= 0) throw Exception('No body for $uri');
7981
if (rs.statusCode != 200) throw Exception('Failed to fetch $uri');

0 commit comments

Comments
 (0)