Skip to content

Commit

Permalink
Merge pull request #159 from detsys-pr-bot/detsys-ts-update-65dd73c56…
Browse files Browse the repository at this point in the history
…2ac60a068340f8e0c040bdcf2c59afe

Update `detsys-ts`: Merge pull request #63 from DeterminateSystems/retry-streams
  • Loading branch information
grahamc committed Sep 4, 2024
2 parents 405d127 + 16669a0 commit 8da9e38
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 25 deletions.
88 changes: 67 additions & 21 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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: {
Expand All @@ -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}`
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -94686,6 +94698,9 @@ var DetSysAction = class {
}
}
return destFile;
} catch (e) {
this.recordPlausibleTimeout(e);
throw e;
} finally {
core.endGroup();
}
Expand All @@ -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();
Expand Down Expand Up @@ -94922,6 +94967,7 @@ var DetSysAction = class {
}
});
} catch (err) {
this.recordPlausibleTimeout(err);
core.debug(
`Error submitting diagnostics event to ${diagnosticsUrl}: ${stringifyError2(err)}`
);
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8da9e38

Please sign in to comment.