From 90d3968e6ce0978099cfa4772179b8c1a4d31764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Mon, 4 May 2026 11:01:41 +0200 Subject: [PATCH] address review comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Cancel discarded response bodies before retrying so the underlying connection can be returned to the pool instead of being held open until the response is garbage collected. - Stop asserting on the rejected error message in the network-error retry test; track rejection via a flag so the test isn't tied to fetch/MSW error strings. Co-Authored-By: Claude Opus 4.7 (1M context) Signed-off-by: Fredrik Adelöw --- .../integration/src/gitlab/GitLabIntegration.test.ts | 12 ++++++------ packages/integration/src/gitlab/GitLabIntegration.ts | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/integration/src/gitlab/GitLabIntegration.test.ts b/packages/integration/src/gitlab/GitLabIntegration.test.ts index 0d817a60c1..dcd2965cb3 100644 --- a/packages/integration/src/gitlab/GitLabIntegration.test.ts +++ b/packages/integration/src/gitlab/GitLabIntegration.test.ts @@ -370,15 +370,15 @@ describe('GitLabIntegration', () => { // Attach the catch handler before advancing timers so the in-flight // rejections don't surface as unhandled. - const caught = integration - .fetch('https://h.com/api/v4') - .catch((e: unknown) => e); + let didReject = false; + const settled = integration.fetch('https://h.com/api/v4').catch(() => { + didReject = true; + }); await jest.advanceTimersByTimeAsync(100); await jest.advanceTimersByTimeAsync(200); - const error = await caught; + await settled; - expect(error).toBeTruthy(); - expect(String(error)).toMatch(/fetch/i); + expect(didReject).toBe(true); expect(callCount).toBe(3); // initial + 2 retries }); }); diff --git a/packages/integration/src/gitlab/GitLabIntegration.ts b/packages/integration/src/gitlab/GitLabIntegration.ts index 9b326f3dea..d76fd0e0cb 100644 --- a/packages/integration/src/gitlab/GitLabIntegration.ts +++ b/packages/integration/src/gitlab/GitLabIntegration.ts @@ -140,6 +140,10 @@ export class GitLabIntegration implements ScmIntegration { ? parseInt(retryAfter, 10) * 1000 : Math.min(100 * Math.pow(2, attempt - 1), 10000); // Exponential backoff, cap at 10 seconds + // Release the underlying connection so it can be reused, since we're + // about to discard this response in favor of a retry. + await response?.body?.cancel().catch(() => {}); + await sleep(delay, abortSignal); } };