Merge remote-tracking branch 'upstream/main' into aeisenberg/ff-refactoring

This commit is contained in:
Andrew Eisenberg 2022-10-12 08:36:16 -07:00
commit 34d48f825c
29 changed files with 185 additions and 89 deletions

View file

@ -1 +1 @@
{ "maximumVersion": "3.7", "minimumVersion": "3.2" }
{ "maximumVersion": "3.7", "minimumVersion": "3.3" }

View file

@ -1,3 +1,3 @@
{
"bundleVersion": "codeql-bundle-20220923"
"bundleVersion": "codeql-bundle-20221010"
}

9
lib/trap-caching.js generated
View file

@ -100,10 +100,11 @@ async function downloadTrapCaches(codeql, languages, logger) {
// The SHA from the base of the PR is the most similar commit we might have a cache for
const preferredKey = await cacheKey(codeql, language, baseSha);
logger.info(`Looking in Actions cache for TRAP cache with key ${preferredKey}`);
const found = await (0, util_1.withTimeout)(MAX_CACHE_OPERATION_MS, cache.restoreCache([cacheDir], preferredKey, [
await cachePrefix(codeql, language), // Fall back to any cache with the right key prefix
]), () => {
logger.info(`Timed out waiting for TRAP cache download for ${language}, will continue without it`);
const found = await cache.restoreCache([cacheDir], preferredKey, [
// Fall back to any cache with the right key prefix
await cachePrefix(codeql, language),
], {
segmentTimeoutInMs: MAX_CACHE_OPERATION_MS,
});
if (found === undefined) {
// We didn't find a TRAP cache in the Actions cache, so the directory on disk is

File diff suppressed because one or more lines are too long

15
lib/util.js generated
View file

@ -725,19 +725,30 @@ exports.tryGetFolderBytes = tryGetFolderBytes;
* Run a promise for a given amount of time, and if it doesn't resolve within
* that time, call the provided callback and then return undefined.
*
* Important: This does NOT cancel the original promise, so that promise will
* continue in the background even after the timeout has expired. If the
* original promise hangs, then this will prevent the process terminating.
*
* @param timeoutMs The timeout in milliseconds.
* @param promise The promise to run.
* @param onTimeout A callback to call if the promise times out.
* @returns The result of the promise, or undefined if the promise times out.
*/
async function withTimeout(timeoutMs, promise, onTimeout) {
let finished = false;
const mainTask = async () => {
const result = await promise;
finished = true;
return result;
};
const timeout = new Promise((resolve) => {
setTimeout(() => {
onTimeout();
if (!finished)
onTimeout();
resolve(undefined);
}, timeoutMs);
});
return await Promise.race([promise, timeout]);
return await Promise.race([mainTask(), timeout]);
}
exports.withTimeout = withTimeout;
//# sourceMappingURL=util.js.map

File diff suppressed because one or more lines are too long

14
lib/util.test.js generated
View file

@ -389,4 +389,18 @@ const shortTime = 10;
t.deepEqual(shortTaskTimedOut, false);
t.deepEqual(result, 99);
});
(0, ava_1.default)("withTimeout doesn't call callback if promise resolves", async (t) => {
let shortTaskTimedOut = false;
const shortTask = new Promise((resolve) => {
setTimeout(() => {
resolve(99);
}, shortTime);
});
const result = await util.withTimeout(100, shortTask, () => {
shortTaskTimedOut = true;
});
await new Promise((r) => setTimeout(r, 200));
t.deepEqual(shortTaskTimedOut, false);
t.deepEqual(result, 99);
});
//# sourceMappingURL=util.test.js.map

File diff suppressed because one or more lines are too long