From d7a7e422e0ba22df0978c72004f16e115d64bd47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20So=C3=B3s?= Date: Thu, 10 Oct 2024 13:55:51 +0200 Subject: [PATCH] More retry on pub_worker: increased delay factor + more exceptions. (#8129) --- pkg/pub_worker/lib/src/analyze.dart | 11 +++++++---- pkg/pub_worker/lib/src/upload.dart | 11 +++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pkg/pub_worker/lib/src/analyze.dart b/pkg/pub_worker/lib/src/analyze.dart index 0930c4849d..e1a0a43951 100644 --- a/pkg/pub_worker/lib/src/analyze.dart +++ b/pkg/pub_worker/lib/src/analyze.dart @@ -32,6 +32,9 @@ const _panaTimeout = Duration(minutes: 50); List 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 || @@ -202,7 +205,7 @@ Future _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, ); @@ -233,7 +236,7 @@ Future _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, ); @@ -258,7 +261,7 @@ Future _reportPackageSkipped( _log.info('api.taskUploadResult("$package", "$version") - skipping'); - final r = await retry( + final r = await _retryOptions.retry( () => api.taskUploadResult(package, version), retryIf: _retryIf, ); @@ -298,7 +301,7 @@ Future _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, ); diff --git a/pkg/pub_worker/lib/src/upload.dart b/pkg/pub_worker/lib/src/upload.dart index 280a0417f5..1bf516173f 100644 --- a/pkg/pub_worker/lib/src/upload.dart +++ b/pkg/pub_worker/lib/src/upload.dart @@ -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'; @@ -60,7 +61,13 @@ Future 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 {