From fa862a6a82606f1e7b0f8d8a76b2f165e00329ca Mon Sep 17 00:00:00 2001 From: Vallie Joseph Date: Mon, 18 Dec 2023 19:12:15 +0000 Subject: [PATCH] testing abort signal --- .../src/internal/download/download-artifact.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/artifact/src/internal/download/download-artifact.ts b/packages/artifact/src/internal/download/download-artifact.ts index a61e2937..5dbd7738 100644 --- a/packages/artifact/src/internal/download/download-artifact.ts +++ b/packages/artifact/src/internal/download/download-artifact.ts @@ -17,6 +17,8 @@ import { } from '../../generated' import {getBackendIdsFromToken} from '../shared/util' import {ArtifactNotFoundError} from '../shared/errors' +import {once} from 'events' +import {sign} from 'crypto' const scrubQueryParameters = (url: string): string => { const parsed = new URL(url) @@ -40,16 +42,23 @@ async function exists(path: string): Promise { async function streamExtract(url: string, directory: string): Promise { const client = new httpClient.HttpClient(getUserAgentString()) const response = await client.get(url) - + const ac = new AbortController() + const signal = ac.signal if (response.message.statusCode !== 200) { throw new Error( `Unexpected HTTP response from blob storage: ${response.message.statusCode} ${response.message.statusMessage}` ) } - return new Promise((resolve, reject) => { response.message .pipe(unzip.Extract({path: directory})) + .once('abort', () => { + signal.addEventListener('abort', () => { + throw new Error( + `Unexpected HTTP response from blob storage: ${response.message.statusCode} ${signal.reason}` + ) + }) + }) .on('close', resolve) .on('error', reject) })