Skip to content

Commit 1d4fc4b

Browse files
committed
Do not retry or panic on upload exceptions when the version is no longer scheduled for analysis.
1 parent 9071b4c commit 1d4fc4b

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

app/lib/task/backend.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,13 +686,14 @@ class TaskBackend {
686686
final key = PackageState.createKey(_db, runtimeVersion, package);
687687
final state = await tx.lookupOrNull<PackageState>(key);
688688
if (state == null || state.versions![version] == null) {
689-
throw NotFoundException.resource('$package/$version');
689+
throw NotAcceptableException(
690+
'$package/$version is no longer selected for analysis.');
690691
}
691692
final versionState = state.versions![version]!;
692693

693694
// Check the secret token
694695
if (!versionState.isAuthorized(_extractBearerToken(request))) {
695-
throw AuthenticationException.authenticationRequired();
696+
throw NotAcceptableException('Secret token is no longer accepted.');
696697
}
697698
assert(versionState.scheduled != initialTimestamp);
698699
assert(versionState.instance != null);

pkg/pub_worker/lib/src/analyze.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ Future<void> analyze(Payload payload) async {
9292
'analyze.',
9393
);
9494
}
95+
} on ResultNotAcceptedUploadException catch (e, st) {
96+
_log.warning(
97+
'failed to upload ${payload.package} / ${p.version}', e, st);
9598
} catch (e, st) {
9699
_log.shout(
97-
'failed to process ${payload.package} / ${p.version}',
98-
e,
99-
st,
100-
);
100+
'failed to process ${payload.package} / ${p.version}', e, st);
101101
}
102102
}
103103
} finally {

pkg/pub_worker/lib/src/upload.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ Future<void> upload(
4040
));
4141
final res = await Response.fromStream(await client.send(req));
4242

43+
// Special case `NotAcceptable` response code, it means that the analysis
44+
// is no longer selected or the secret token timed out / was replaced
45+
// (it may need a different analysis round).
46+
if (res.statusCode == 406) {
47+
_log.warning('Failed to upload: $filename, status = ${res.statusCode}');
48+
throw ResultNotAcceptedUploadException(res.body);
49+
}
4350
if (400 <= res.statusCode && res.statusCode < 500) {
4451
_log.shout('Failed to upload: $filename, status = ${res.statusCode}');
4552
throw UploadException(
@@ -80,3 +87,7 @@ final class UploadException implements Exception {
8087
final class IntermittentUploadException extends UploadException {
8188
IntermittentUploadException(String message) : super(message);
8289
}
90+
91+
final class ResultNotAcceptedUploadException extends UploadException {
92+
ResultNotAcceptedUploadException(String message) : super(message);
93+
}

0 commit comments

Comments
 (0)