From b40cadf8b2ca40251c3cbb9d2e739b77a7c55ac3 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Thu, 13 Feb 2025 18:11:46 +0100 Subject: [PATCH] More insights from S3 client when fetching from S3 and R2 (#6513) --- .../cdn-worker/src/artifact-storage-reader.ts | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/packages/services/cdn-worker/src/artifact-storage-reader.ts b/packages/services/cdn-worker/src/artifact-storage-reader.ts index 62b955769..ddb14f0a4 100644 --- a/packages/services/cdn-worker/src/artifact-storage-reader.ts +++ b/packages/services/cdn-worker/src/artifact-storage-reader.ts @@ -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')