nomagick commited on
Commit
f0c3a9b
·
unverified ·
1 Parent(s): a66791d
backend/functions/package-lock.json CHANGED
@@ -38,7 +38,7 @@
38
  "robots-parser": "^3.0.1",
39
  "set-cookie-parser": "^2.6.0",
40
  "stripe": "^11.11.0",
41
- "tiktoken": "^1.0.10",
42
  "tld-extract": "^2.1.0",
43
  "turndown": "^7.1.3",
44
  "turndown-plugin-gfm": "^1.0.2",
@@ -11218,9 +11218,9 @@
11218
  }
11219
  },
11220
  "node_modules/tiktoken": {
11221
- "version": "1.0.13",
11222
- "resolved": "https://registry.npmjs.org/tiktoken/-/tiktoken-1.0.13.tgz",
11223
- "integrity": "sha512-JaL9ZnvTbGFMDIBeGdVkLt4qWTeCPw+n7Ock+wceAGRenuHA6nOOvMJFliNDyXsjg2osGKJWsXtO2xc74VxyDw=="
11224
  },
11225
  "node_modules/tiny-lru": {
11226
  "version": "11.2.5",
 
38
  "robots-parser": "^3.0.1",
39
  "set-cookie-parser": "^2.6.0",
40
  "stripe": "^11.11.0",
41
+ "tiktoken": "^1.0.16",
42
  "tld-extract": "^2.1.0",
43
  "turndown": "^7.1.3",
44
  "turndown-plugin-gfm": "^1.0.2",
 
11218
  }
11219
  },
11220
  "node_modules/tiktoken": {
11221
+ "version": "1.0.16",
11222
+ "resolved": "https://registry.npmjs.org/tiktoken/-/tiktoken-1.0.16.tgz",
11223
+ "integrity": "sha512-hRcORIGF2YlAgWx3nzrGJOrKSJwLoc81HpXmMQk89632XAgURc7IeV2FgQ2iXo9z/J96fCvpsHg2kWoHcbj9fg=="
11224
  },
11225
  "node_modules/tiny-lru": {
11226
  "version": "11.2.5",
backend/functions/package.json CHANGED
@@ -58,7 +58,7 @@
58
  "robots-parser": "^3.0.1",
59
  "set-cookie-parser": "^2.6.0",
60
  "stripe": "^11.11.0",
61
- "tiktoken": "^1.0.10",
62
  "tld-extract": "^2.1.0",
63
  "turndown": "^7.1.3",
64
  "turndown-plugin-gfm": "^1.0.2",
 
58
  "robots-parser": "^3.0.1",
59
  "set-cookie-parser": "^2.6.0",
60
  "stripe": "^11.11.0",
61
+ "tiktoken": "^1.0.16",
62
  "tld-extract": "^2.1.0",
63
  "turndown": "^7.1.3",
64
  "turndown-plugin-gfm": "^1.0.2",
backend/functions/src/services/puppeteer.ts CHANGED
@@ -225,9 +225,17 @@ export class PuppeteerControl extends AsyncService {
225
  super(...arguments);
226
  this.setMaxListeners(2 * Math.floor(os.totalmem() / (256 * 1024 * 1024)) + 1); 148 - 95;
227
 
 
228
  this.on('crippled', () => {
 
229
  this.__loadedPage.length = 0;
230
  this.livePages.clear();
 
 
 
 
 
 
231
  });
232
  }
233
 
@@ -257,7 +265,9 @@ export class PuppeteerControl extends AsyncService {
257
  });
258
  this.browser.once('disconnected', () => {
259
  this.logger.warn(`Browser disconnected`);
260
- this.emit('crippled');
 
 
261
  process.nextTick(() => this.serviceReady());
262
  });
263
  this.logger.info(`Browser launched: ${this.browser.process()?.pid}`);
@@ -287,13 +297,14 @@ export class PuppeteerControl extends AsyncService {
287
 
288
  async newPage() {
289
  await this.serviceReady();
290
- const dedicatedContext = await this.browser.createBrowserContext();
291
  const sn = this._sn++;
292
  let page;
293
  try {
 
294
  page = await dedicatedContext.newPage();
295
  } catch (err: any) {
296
  this.logger.warn(`Failed to create page ${sn}`, { err: marshalErrorLike(err) });
 
297
  throw new ServiceNodeResourceDrainError(`This specific worker node failed to open a new page, try again.`);
298
  }
299
  const preparations = [];
 
225
  super(...arguments);
226
  this.setMaxListeners(2 * Math.floor(os.totalmem() / (256 * 1024 * 1024)) + 1); 148 - 95;
227
 
228
+ let crippledTimes = 0;
229
  this.on('crippled', () => {
230
+ crippledTimes += 1;
231
  this.__loadedPage.length = 0;
232
  this.livePages.clear();
233
+ if (crippledTimes > 5) {
234
+ process.nextTick(() => {
235
+ this.emit('error', new Error('Browser crashed too many times, quitting...'));
236
+ // process.exit(1);
237
+ });
238
+ }
239
  });
240
  }
241
 
 
265
  });
266
  this.browser.once('disconnected', () => {
267
  this.logger.warn(`Browser disconnected`);
268
+ if (this.browser) {
269
+ this.emit('crippled');
270
+ }
271
  process.nextTick(() => this.serviceReady());
272
  });
273
  this.logger.info(`Browser launched: ${this.browser.process()?.pid}`);
 
297
 
298
  async newPage() {
299
  await this.serviceReady();
 
300
  const sn = this._sn++;
301
  let page;
302
  try {
303
+ const dedicatedContext = await this.browser.createBrowserContext();
304
  page = await dedicatedContext.newPage();
305
  } catch (err: any) {
306
  this.logger.warn(`Failed to create page ${sn}`, { err: marshalErrorLike(err) });
307
+ this.browser.process()?.kill('SIGKILL');
308
  throw new ServiceNodeResourceDrainError(`This specific worker node failed to open a new page, try again.`);
309
  }
310
  const preparations = [];
thinapps-shared CHANGED
@@ -1 +1 @@
1
- Subproject commit c2a3af9607d6a0ada64639d4f4e73bfc9c3e024f
 
1
+ Subproject commit d91b3aab5924c4090cff0d9d6cde9c5c0a4dc8bd