@@ -25,6 +25,7 @@ Future<void> main(List<String> args) async {
25
25
print ('Done.' );
26
26
}
27
27
28
+ final timeLimit = Duration (seconds: 15 );
28
29
final urls = < String > [
29
30
// package info
30
31
'https://pub.dev/api/packages/http' ,
@@ -42,12 +43,13 @@ Future<void> _checkHosts() async {
42
43
for (final type in [InternetAddressType .IPv4 , InternetAddressType .IPv6 ]) {
43
44
final typeStr = type == InternetAddressType .IPv4 ? 'IPv4' : 'IPv6' ;
44
45
try {
45
- final addresses = await InternetAddress .lookup (host, type: type);
46
+ final addresses =
47
+ await InternetAddress .lookup (host, type: type).timeout (timeLimit);
46
48
final failed = < InternetAddress > [];
47
49
for (final address in addresses) {
48
50
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) ;
51
53
} catch (_) {
52
54
failed.add (address);
53
55
}
@@ -71,9 +73,9 @@ Future<void> _checkUrls({HttpClient? client}) async {
71
73
Future <void > _checkUrlGetContent (Uri uri, {HttpClient ? client}) async {
72
74
final closeClient = client == null ;
73
75
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) ;
77
79
final bodyLength = bodyList.map ((e) => e.length).reduce ((a, b) => a + b);
78
80
if (bodyLength <= 0 ) throw Exception ('No body for $uri ' );
79
81
if (rs.statusCode != 200 ) throw Exception ('Failed to fetch $uri ' );
0 commit comments