Skip to content

Commit

Permalink
fix: remove node@14 specific extract timeout (#5816)
Browse files Browse the repository at this point in the history
closes #5719

Original stream.pipeline issue has been fixed in Node 14.1.0 and above.

Meanwhile, the workaround itself caused timout failures in many CI Node 14 runs, as reported in #5719.

Removed it, as it's no longer needed, and actually blocks consumers from adding CI testing on Node 14.
  • Loading branch information
AviVahl committed May 7, 2020
1 parent 5115482 commit 70d5c7f
Showing 1 changed file with 2 additions and 45 deletions.
47 changes: 2 additions & 45 deletions src/BrowserFetcher.ts
Expand Up @@ -22,7 +22,7 @@ import * as childProcess from 'child_process';
import * as https from 'https';
import * as http from 'http';

import * as extract from 'extract-zip';
import * as extractZip from 'extract-zip';
import * as debug from 'debug';
import * as removeRecursive from 'rimraf';
import * as URL from 'url';
Expand Down Expand Up @@ -307,7 +307,7 @@ function downloadFile(url: string, destinationPath: string, progressCallback: (x
function install(archivePath: string, folderPath: string): Promise<unknown> {
debugFetcher(`Installing ${archivePath} to ${folderPath}`);
if (archivePath.endsWith('.zip'))
return extractZip(archivePath, folderPath);
return extractZip(archivePath, {dir: folderPath});
else if (archivePath.endsWith('.tar.bz2'))
return extractTar(archivePath, folderPath);
else if (archivePath.endsWith('.dmg'))
Expand All @@ -316,49 +316,6 @@ function install(archivePath: string, folderPath: string): Promise<unknown> {
throw new Error(`Unsupported archive format: ${archivePath}`);
}

async function extractZip(zipPath: string, folderPath: string): Promise<void> {
const nodeVersion = process.version;

/* There is currently a bug with extract-zip and Node v14.0.0 that
* causes extractZip to silently fail:
* https://github.com/puppeteer/puppeteer/issues/5719
*
* Rather than silenty fail if the user is on Node 14 we instead
* detect that and throw an error directing the user to that bug. The
* rejection message below is surfaced to the user in the command
* line.
*
* The issue seems to be in streams never resolving so we wrap the
* call in a timeout and give it 10s to resolve before deciding on
* an error.
*
* If the user is on Node < 14 we maintain the behaviour we had before
* this patch.
*/
if (nodeVersion.startsWith('v14.')) {
let timeoutReject;
const timeoutPromise = new Promise((resolve, reject) => { timeoutReject = reject; });

const timeoutToken = setTimeout(() => {
const error = new Error(`Puppeteer currently does not work on Node v14 due to an upstream bug. Please see: https://github.com/puppeteer/puppeteer/issues/5719 for details.`);
timeoutReject(error);
}, 10 * 1000);

await Promise.race([
extract(zipPath, {dir: folderPath}),
timeoutPromise
]);

clearTimeout(timeoutToken);
} else {
try {
await extract(zipPath, {dir: folderPath});
} catch (error) {
return error;
}
}
}

/**
* @param {string} tarPath
* @param {string} folderPath
Expand Down

0 comments on commit 70d5c7f

Please sign in to comment.