Skip to content

Commit db7b089

Browse files
authored
Merge pull request #5 from gruppin/increase_trees_timeout
increase timeouts
2 parents 011e77a + c09cda5 commit db7b089

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

server/api/lib/challanged-file.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const Log = require('../lib/log');
77
const GOV_IL_BASE = 'https://www.gov.il';
88
const USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36';
99
const DELAY_BETWEEN_REQUESTS_MS = 2000;
10+
const DOWNLOAD_BEGIN_TIMEOUT_MS = 60000; // time to wait for download to start
11+
const DOWNLOAD_COMPLETE_TIMEOUT_MS = 180000; // time to wait for download to finish
1012

1113
const launchStealthBrowser = async () => {
1214
const browser = await puppeteer.launch({
@@ -51,9 +53,9 @@ const downloadWithNavigation = async (page, client, url, file) => {
5153
() => {
5254
client.off('Browser.downloadWillBegin', onBegin);
5355
client.off('Browser.downloadProgress', onProgress);
54-
reject(new Error(`Download did not begin within 20s for ${url} — server may have blocked the request`));
56+
reject(new Error(`Download did not begin within ${DOWNLOAD_BEGIN_TIMEOUT_MS / 1000}s for ${url} — server may have blocked the request`));
5557
},
56-
20000
58+
DOWNLOAD_BEGIN_TIMEOUT_MS
5759
);
5860

5961
let guid = null;
@@ -93,7 +95,7 @@ const downloadWithNavigation = async (page, client, url, file) => {
9395

9496
const downloadedPath = await Promise.race([
9597
downloadedPathPromise,
96-
new Promise((_, reject) => setTimeout(() => reject(new Error(`Download timed out after 60s for ${url}`)), 60000))
98+
new Promise((_, reject) => setTimeout(() => reject(new Error(`Download timed out after ${DOWNLOAD_COMPLETE_TIMEOUT_MS / 1000}s for ${url}`)), DOWNLOAD_COMPLETE_TIMEOUT_MS))
9799
]);
98100

99101
const content = fs.readFileSync(downloadedPath);
@@ -121,7 +123,7 @@ const createDownloadSession = async (baseUrl) => {
121123
const page = await setupStealthPage(browser);
122124

123125
Log.info(`createDownloadSession: establishing session on ${baseUrl}`);
124-
await page.goto(baseUrl, { waitUntil: 'networkidle2', timeout: 30000 });
126+
await page.goto(baseUrl, { waitUntil: 'networkidle2', timeout: 60000 });
125127

126128
// Create CDP session once and reuse — avoids Target.attachToTarget timeout on long runs
127129
const client = await page.createCDPSession();
@@ -165,7 +167,7 @@ const downloadChallengedFile = async (url, file) => {
165167
const page = await setupStealthPage(browser);
166168

167169
if (url.startsWith(GOV_IL_BASE)) {
168-
await page.goto(GOV_IL_BASE, { waitUntil: 'networkidle2', timeout: 30000 });
170+
await page.goto(GOV_IL_BASE, { waitUntil: 'networkidle2', timeout: 60000 });
169171
}
170172

171173
const client = await page.createCDPSession();

0 commit comments

Comments
 (0)