Skip to content

Commit d7a7e42

Browse files
authored
More retry on pub_worker: increased delay factor + more exceptions. (#8129)
1 parent d5c64ed commit d7a7e42

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

pkg/pub_worker/lib/src/analyze.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ const _panaTimeout = Duration(minutes: 50);
3232

3333
List<int> encodeJson(Object json) => JsonUtf8Encoder().convert(json);
3434

35+
/// Retry requests with a longer delay between them.
36+
final _retryOptions = RetryOptions(delayFactor: Duration(seconds: 5));
37+
3538
/// Retry request if it fails because of an [IOException] or status is 5xx.
3639
bool _retryIf(Exception e) =>
3740
e is IOException ||
@@ -202,7 +205,7 @@ Future<void> _analyzePackage(
202205

203206
// Upload results, if there is any
204207
_log.info('api.taskUploadResult("$package", "$version")');
205-
final r = await retry(
208+
final r = await _retryOptions.retry(
206209
() => api.taskUploadResult(package, version),
207210
retryIf: _retryIf,
208211
);
@@ -233,7 +236,7 @@ Future<void> _analyzePackage(
233236

234237
// Report that we're done processing the package / version.
235238
_log.info('api.taskUploadFinished("$package", "$version")');
236-
await retry(
239+
await _retryOptions.retry(
237240
() => api.taskUploadFinished(package, version),
238241
retryIf: _retryIf,
239242
);
@@ -258,7 +261,7 @@ Future<void> _reportPackageSkipped(
258261

259262
_log.info('api.taskUploadResult("$package", "$version") - skipping');
260263

261-
final r = await retry(
264+
final r = await _retryOptions.retry(
262265
() => api.taskUploadResult(package, version),
263266
retryIf: _retryIf,
264267
);
@@ -298,7 +301,7 @@ Future<void> _reportPackageSkipped(
298301

299302
// Report that we're done processing the package / version.
300303
_log.info('api.taskUploadFinished("$package", "$version") - skipped');
301-
await retry(
304+
await _retryOptions.retry(
302305
() => api.taskUploadFinished(package, version),
303306
retryIf: _retryIf,
304307
);

pkg/pub_worker/lib/src/upload.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:async';
56
import 'dart:io';
67

78
import 'package:_pub_shared/data/package_api.dart' show UploadInfo;
89
import 'package:http/http.dart'
9-
show MultipartRequest, MultipartFile, Client, Response;
10+
show Client, ClientException, MultipartFile, MultipartRequest, Response;
1011
import 'package:http_parser/http_parser.dart' show MediaType;
1112
import 'package:logging/logging.dart' show Logger;
1213
import 'package:meta/meta.dart';
@@ -60,7 +61,13 @@ Future<void> upload(
6061
throw UploadException(
6162
'Unhandled HTTP status = ${res.statusCode}, body: ${res.body}',
6263
);
63-
}, retryIf: (e) => e is IOException || e is IntermittentUploadException);
64+
},
65+
retryIf: (e) =>
66+
e is IOException ||
67+
e is IntermittentUploadException ||
68+
e is ClientException ||
69+
e is TimeoutException,
70+
delayFactor: Duration(seconds: 5));
6471

6572
@sealed
6673
class UploadException implements Exception {

0 commit comments

Comments
 (0)