From 16669a0427d20bbfd5e88037b84b9e6e4bf7ed97 Mon Sep 17 00:00:00 2001 From: grahamc <76716+grahamc@users.noreply.github.com> Date: Wed, 4 Sep 2024 18:05:56 +0000 Subject: [PATCH] Update `detsys-ts` for: `Merge pull request #63 from DeterminateSystems/retry-streams` (`65dd73c562ac60a068340f8e0c040bdcf2c59afe`) --- dist/index.js | 88 ++++++++++++++++++++++++++++++++++++++------------ pnpm-lock.yaml | 8 ++--- 2 files changed, 71 insertions(+), 25 deletions(-) diff --git a/dist/index.js b/dist/index.js index fb69a9f..2352079 100644 --- a/dist/index.js +++ b/dist/index.js @@ -93419,9 +93419,7 @@ var cache = __nccwpck_require__(6878); const external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:child_process"); ;// CONCATENATED MODULE: external "node:path" const external_node_path_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:path"); -;// CONCATENATED MODULE: external "node:stream/promises" -const external_node_stream_promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:stream/promises"); -;// CONCATENATED MODULE: ./node_modules/.pnpm/detsys-ts@https+++codeload.github.com+DeterminateSystems+detsys-ts+tar.gz+817e4d4123b6fb4eae5_xidqcuah7tnxkzkfyksdcuh3ni/node_modules/detsys-ts/dist/index.js +;// CONCATENATED MODULE: ./node_modules/.pnpm/detsys-ts@https+++codeload.github.com+DeterminateSystems+detsys-ts+tar.gz+65dd73c562ac60a0683_pugfuojoota6b26hy6vcd3ndou/node_modules/detsys-ts/dist/index.js var __defProp = Object.defineProperty; var __export = (target, all) => { for (var name in all) @@ -93895,7 +93893,7 @@ var ALLOWED_SUFFIXES = [ ]; var DEFAULT_IDS_HOST = "https://install.determinate.systems"; var LOOKUP = process.env["IDS_LOOKUP"] ?? DEFAULT_LOOKUP; -var DEFAULT_TIMEOUT = 3e4; +var DEFAULT_TIMEOUT = 1e4; var IdsHost = class { constructor(idsProjectName, diagnosticsSuffix, runtimeDiagnosticsUrl) { this.idsProjectName = idsProjectName; @@ -93910,7 +93908,7 @@ var IdsHost = class { request: DEFAULT_TIMEOUT }, retry: { - limit: (await this.getUrlsByPreference()).length, + limit: Math.max((await this.getUrlsByPreference()).length, 3), methods: ["GET", "HEAD"] }, hooks: { @@ -93920,7 +93918,7 @@ var IdsHost = class { this.markCurrentHostBroken(); const nextUrl = await this.getRootUrl(); if (recordFailoverCallback !== void 0) { - recordFailoverCallback(prevUrl, nextUrl); + recordFailoverCallback(error3, prevUrl, nextUrl); } core.info( `Retrying after error ${error3.code}, retry #: ${retryCount}` @@ -94306,8 +94304,8 @@ var STATE_KEY_NIX_NOT_FOUND = "detsys_action_nix_not_found"; var STATE_NOT_FOUND = "not-found"; var STATE_KEY_CROSS_PHASE_ID = "detsys_cross_phase_id"; var STATE_BACKTRACE_START_TIMESTAMP = "detsys_backtrace_start_timestamp"; -var DIAGNOSTIC_ENDPOINT_TIMEOUT_MS = 3e4; -var CHECK_IN_ENDPOINT_TIMEOUT_MS = 5e3; +var DIAGNOSTIC_ENDPOINT_TIMEOUT_MS = 1e4; +var CHECK_IN_ENDPOINT_TIMEOUT_MS = 1e3; var DetSysAction = class { determineExecutionPhase() { const currentPhase = core.getState(STATE_KEY_EXECUTION_PHASE); @@ -94531,12 +94529,15 @@ var DetSysAction = class { } } async getClient() { - return await this.idsHost.getGot((prevUrl, nextUrl) => { - this.recordEvent("ids-failover", { - previousUrl: prevUrl.toString(), - nextUrl: nextUrl.toString() - }); - }); + return await this.idsHost.getGot( + (incitingError, prevUrl, nextUrl) => { + this.recordPlausibleTimeout(incitingError); + this.recordEvent("ids-failover", { + previousUrl: prevUrl.toString(), + nextUrl: nextUrl.toString() + }); + } + ); } async checkIn() { const checkin = await this.requestCheckIn(); @@ -94620,12 +94621,27 @@ var DetSysAction = class { } }).json(); } catch (e) { + this.recordPlausibleTimeout(e); core.debug(`Error checking in: ${stringifyError2(e)}`); this.idsHost.markCurrentHostBroken(); } } return void 0; } + recordPlausibleTimeout(e) { + if (e instanceof TimeoutError && "timings" in e && "request" in e) { + const reportContext = { + url: e.request.requestUrl?.toString(), + retry_count: e.request.retryCount + }; + for (const [key, value] of Object.entries(e.timings.phases)) { + if (Number.isFinite(value)) { + reportContext[`timing_phase_${key}`] = value; + } + } + this.recordEvent("timeout", reportContext); + } + } /** * Fetch an artifact, such as a tarball, from the location determined by the * `source-*` inputs. If `source-binary` is specified, this will return a path @@ -94669,13 +94685,9 @@ var DetSysAction = class { `No match from the cache, re-fetching from the redirect: ${versionCheckup.url}` ); const destFile = this.getTemporaryName(); - const fetchStream = (await this.getClient()).stream(versionCheckup.url); - await (0,external_node_stream_promises_namespaceObject.pipeline)( - fetchStream, - (0,external_node_fs_namespaceObject.createWriteStream)(destFile, { - encoding: "binary", - mode: 493 - }) + const fetchStream = await this.downloadFile( + new URL(versionCheckup.url), + destFile ); if (fetchStream.response?.headers.etag) { const v = fetchStream.response.headers.etag; @@ -94686,6 +94698,9 @@ var DetSysAction = class { } } return destFile; + } catch (e) { + this.recordPlausibleTimeout(e); + throw e; } finally { core.endGroup(); } @@ -94699,6 +94714,36 @@ var DetSysAction = class { core.setFailed(`strict mode failure: ${msg}`); } } + async downloadFile(url, destination) { + const client = await this.getClient(); + return new Promise((resolve, reject) => { + let writeStream; + let failed = false; + const retry = (stream) => { + if (writeStream) { + writeStream.destroy(); + } + writeStream = (0,external_node_fs_namespaceObject.createWriteStream)(destination, { + encoding: "binary", + mode: 493 + }); + writeStream.once("error", (error3) => { + failed = true; + reject(error3); + }); + writeStream.on("finish", () => { + if (!failed) { + resolve(stream); + } + }); + stream.once("retry", (_count, _error, createRetryStream) => { + retry(createRetryStream()); + }); + stream.pipe(writeStream); + }; + retry(client.stream(url)); + }); + } async complete() { this.recordEvent(`complete_${this.executionPhase}`); await this.submitEvents(); @@ -94922,6 +94967,7 @@ var DetSysAction = class { } }); } catch (err) { + this.recordPlausibleTimeout(err); core.debug( `Error submitting diagnostics event to ${diagnosticsUrl}: ${stringifyError2(err)}` ); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e726c0c..c3916c3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,7 +16,7 @@ importers: version: 1.1.1 detsys-ts: specifier: github:DeterminateSystems/detsys-ts - version: https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/817e4d4123b6fb4eae5aa557658f25f8539e7240 + version: https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/65dd73c562ac60a068340f8e0c040bdcf2c59afe devDependencies: '@trivago/prettier-plugin-sort-imports': specifier: ^4.3.0 @@ -828,8 +828,8 @@ packages: resolution: {integrity: sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==} engines: {node: '>=6'} - detsys-ts@https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/817e4d4123b6fb4eae5aa557658f25f8539e7240: - resolution: {tarball: https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/817e4d4123b6fb4eae5aa557658f25f8539e7240} + detsys-ts@https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/65dd73c562ac60a068340f8e0c040bdcf2c59afe: + resolution: {tarball: https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/65dd73c562ac60a068340f8e0c040bdcf2c59afe} version: 1.0.0 dir-glob@3.0.1: @@ -2868,7 +2868,7 @@ snapshots: dequal@2.0.3: {} - detsys-ts@https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/817e4d4123b6fb4eae5aa557658f25f8539e7240: + detsys-ts@https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/65dd73c562ac60a068340f8e0c040bdcf2c59afe: dependencies: '@actions/cache': 3.2.4 '@actions/core': 1.10.1