More insights from S3 client when fetching from S3 and R2 (#6513)

This commit is contained in:
Kamil Kisiela 2025-02-13 18:11:46 +01:00 committed by GitHub
parent 5c3bbd39b8
commit b40cadf8b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -148,9 +148,10 @@ export class ArtifactStorageReader {
const abortOtherRequest = (ctrl: AbortController, source: string) => {
return (res: Response) => {
this.breadcrumb(`Successful fetch from "${source}", aborting other request`);
// abort other pending request
const error = new PendingRequestAbortedError();
ctrl.abort(error);
if (!ctrl.signal.aborted) {
// abort other pending request
ctrl.abort(new PendingRequestAbortedError());
}
return res;
};
@ -183,7 +184,11 @@ export class ArtifactStorageReader {
});
},
})
.then(abortOtherRequest(mirrorController, 'primary')),
.then(abortOtherRequest(mirrorController, 'primary'))
.catch(error => {
this.breadcrumb(`Failed to fetch from primary (error=${stringifyError(error)})`);
return Promise.reject(error);
}),
this.s3Mirror.client
.fetch(mirrorObjectEndpoint, {
method: args.method,
@ -202,8 +207,22 @@ export class ArtifactStorageReader {
});
},
})
.then(abortOtherRequest(primaryController, 'mirror')),
]);
.then(abortOtherRequest(primaryController, 'mirror'))
.catch(error => {
this.breadcrumb(`Failed to fetch from mirror (error=${stringifyError(error)})`);
return Promise.reject(error);
}),
]).catch(error => {
this.breadcrumb(`Both requests failed: ${stringifyError(error)}`);
if (error instanceof AggregateError && error.errors) {
for (let i = 0; i < error.errors.length; i++) {
this.breadcrumb(`Request ${i} failed: ${stringifyError(error.errors[i])}`);
}
}
return Promise.reject(error);
});
});
}
@ -446,7 +465,7 @@ export class ArtifactStorageReader {
this.analytics?.track(
{
type: args.isMirror ? 'r2' : 's3',
type: args.isMirror ? 's3' : 'r2',
statusCodeOrErrCode:
args.result.type === 'error'
? String(args.result.error.name ?? 'unknown')