From 715b1acc05966f1b2eb21ada2b1c9acdda73455e Mon Sep 17 00:00:00 2001 From: Rob Herley Date: Wed, 6 Dec 2023 23:42:07 +0000 Subject: [PATCH 1/3] cleanup artifact handlers hanging node process --- .../src/internal/shared/artifact-twirp-client.ts | 15 +++++++++------ .../src/internal/upload/upload-artifact.ts | 10 +++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/artifact/src/internal/shared/artifact-twirp-client.ts b/packages/artifact/src/internal/shared/artifact-twirp-client.ts index dde3d4a4..c59fcc0f 100644 --- a/packages/artifact/src/internal/shared/artifact-twirp-client.ts +++ b/packages/artifact/src/internal/shared/artifact-twirp-client.ts @@ -59,10 +59,10 @@ class ArtifactHttpClient implements Rpc { 'Content-Type': contentType } try { - const response = await this.retryableRequest(async () => + const {body} = await this.retryableRequest(async () => this.httpClient.post(url, JSON.stringify(data), headers) ) - const body = await response.readBody() + return JSON.parse(body) } catch (error) { throw new Error(`Failed to ${method}: ${error.message}`) @@ -71,7 +71,7 @@ class ArtifactHttpClient implements Rpc { async retryableRequest( operation: () => Promise - ): Promise { + ): Promise<{response: HttpClientResponse, body: string}> { let attempt = 0 let errorMessage = '' while (attempt < this.maxAttempts) { @@ -80,11 +80,14 @@ class ArtifactHttpClient implements Rpc { try { const response = await operation() const statusCode = response.message.statusCode - debug(`[Response] ${response.message.statusCode}`) - debug(JSON.stringify(response.message.headers, null, 2)) + const raw = await response.readBody() + const body = JSON.parse(raw) + debug(`[Response] - ${response.message.statusCode}`) + debug(`Headers: ${JSON.stringify(response.message.headers, null, 2)}`) + debug(`Body: ${JSON.stringify(body, null, 2)}`) if (this.isSuccessStatusCode(statusCode)) { - return response + return {response, body} } isRetryable = this.isRetryableHttpStatusCode(statusCode) diff --git a/packages/artifact/src/internal/upload/upload-artifact.ts b/packages/artifact/src/internal/upload/upload-artifact.ts index 55921252..e880102f 100644 --- a/packages/artifact/src/internal/upload/upload-artifact.ts +++ b/packages/artifact/src/internal/upload/upload-artifact.ts @@ -40,11 +40,6 @@ export async function uploadArtifact( ) } - const zipUploadStream = await createZipUploadStream( - zipSpecification, - options?.compressionLevel - ) - // get the IDs needed for the artifact creation const backendIds = getBackendIdsFromToken() @@ -73,6 +68,11 @@ export async function uploadArtifact( ) } + const zipUploadStream = await createZipUploadStream( + zipSpecification, + options?.compressionLevel + ) + // Upload zip to blob storage const uploadResult = await uploadZipToBlobStorage( createArtifactResp.signedUploadUrl, From 8c317a0e59177696981abfbbe86f04f4599ff08e Mon Sep 17 00:00:00 2001 From: Rob Herley Date: Wed, 6 Dec 2023 23:51:16 +0000 Subject: [PATCH 2/3] one too many parses --- .../artifact/src/internal/shared/artifact-twirp-client.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/artifact/src/internal/shared/artifact-twirp-client.ts b/packages/artifact/src/internal/shared/artifact-twirp-client.ts index c59fcc0f..1e981675 100644 --- a/packages/artifact/src/internal/shared/artifact-twirp-client.ts +++ b/packages/artifact/src/internal/shared/artifact-twirp-client.ts @@ -80,11 +80,10 @@ class ArtifactHttpClient implements Rpc { try { const response = await operation() const statusCode = response.message.statusCode - const raw = await response.readBody() - const body = JSON.parse(raw) + const body = await response.readBody() debug(`[Response] - ${response.message.statusCode}`) debug(`Headers: ${JSON.stringify(response.message.headers, null, 2)}`) - debug(`Body: ${JSON.stringify(body, null, 2)}`) + debug(`Body: ${body}`) if (this.isSuccessStatusCode(statusCode)) { return {response, body} From f732e4cd62275a56d1fd95a3ad2f24204d8b4e46 Mon Sep 17 00:00:00 2001 From: Rob Herley Date: Wed, 6 Dec 2023 23:57:33 +0000 Subject: [PATCH 3/3] linter --- .../artifact/src/internal/shared/artifact-twirp-client.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/artifact/src/internal/shared/artifact-twirp-client.ts b/packages/artifact/src/internal/shared/artifact-twirp-client.ts index 1e981675..9166e799 100644 --- a/packages/artifact/src/internal/shared/artifact-twirp-client.ts +++ b/packages/artifact/src/internal/shared/artifact-twirp-client.ts @@ -62,7 +62,7 @@ class ArtifactHttpClient implements Rpc { const {body} = await this.retryableRequest(async () => this.httpClient.post(url, JSON.stringify(data), headers) ) - + return JSON.parse(body) } catch (error) { throw new Error(`Failed to ${method}: ${error.message}`) @@ -71,7 +71,7 @@ class ArtifactHttpClient implements Rpc { async retryableRequest( operation: () => Promise - ): Promise<{response: HttpClientResponse, body: string}> { + ): Promise<{response: HttpClientResponse; body: string}> { let attempt = 0 let errorMessage = '' while (attempt < this.maxAttempts) {