Skip to content

Commit

Permalink
More retry on pub_worker: increased delay factor + more exceptions. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Oct 10, 2024
1 parent d5c64ed commit d7a7e42
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 7 additions & 4 deletions pkg/pub_worker/lib/src/analyze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const _panaTimeout = Duration(minutes: 50);

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

/// Retry requests with a longer delay between them.
final _retryOptions = RetryOptions(delayFactor: Duration(seconds: 5));

/// Retry request if it fails because of an [IOException] or status is 5xx.
bool _retryIf(Exception e) =>
e is IOException ||
Expand Down Expand Up @@ -202,7 +205,7 @@ Future<void> _analyzePackage(

// Upload results, if there is any
_log.info('api.taskUploadResult("$package", "$version")');
final r = await retry(
final r = await _retryOptions.retry(
() => api.taskUploadResult(package, version),
retryIf: _retryIf,
);
Expand Down Expand Up @@ -233,7 +236,7 @@ Future<void> _analyzePackage(

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

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

final r = await retry(
final r = await _retryOptions.retry(
() => api.taskUploadResult(package, version),
retryIf: _retryIf,
);
Expand Down Expand Up @@ -298,7 +301,7 @@ Future<void> _reportPackageSkipped(

// Report that we're done processing the package / version.
_log.info('api.taskUploadFinished("$package", "$version") - skipped');
await retry(
await _retryOptions.retry(
() => api.taskUploadFinished(package, version),
retryIf: _retryIf,
);
Expand Down
11 changes: 9 additions & 2 deletions pkg/pub_worker/lib/src/upload.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:io';

import 'package:_pub_shared/data/package_api.dart' show UploadInfo;
import 'package:http/http.dart'
show MultipartRequest, MultipartFile, Client, Response;
show Client, ClientException, MultipartFile, MultipartRequest, Response;
import 'package:http_parser/http_parser.dart' show MediaType;
import 'package:logging/logging.dart' show Logger;
import 'package:meta/meta.dart';
Expand Down Expand Up @@ -60,7 +61,13 @@ Future<void> upload(
throw UploadException(
'Unhandled HTTP status = ${res.statusCode}, body: ${res.body}',
);
}, retryIf: (e) => e is IOException || e is IntermittentUploadException);
},
retryIf: (e) =>
e is IOException ||
e is IntermittentUploadException ||
e is ClientException ||
e is TimeoutException,
delayFactor: Duration(seconds: 5));

@sealed
class UploadException implements Exception {
Expand Down

0 comments on commit d7a7e42

Please sign in to comment.