nomagick commited on
Commit
55b954f
·
unverified ·
1 Parent(s): 528b3e5

fix: tweak health check

Browse files
backend/functions/src/services/puppeteer.ts CHANGED
@@ -151,21 +151,24 @@ export class PuppeteerControl extends AsyncService {
151
 
152
  @maxConcurrency(1)
153
  async healthCheck() {
154
- const healthyPage = await Promise.race([this.pagePool.acquire(3), delay(60_000).then(() => null)]).catch((err) => {
155
- this.logger.error(`Health check failed`, { err: marshalErrorLike(err) });
 
156
  return null;
157
  });
 
158
 
159
  if (healthyPage) {
160
  this.pagePool.release(healthyPage);
161
  return;
162
  }
163
 
164
- this.logger.warn(`Health check failed, trying to clean up.`);
165
  await this.pagePool.clear();
166
  this.browser.process()?.kill('SIGKILL');
167
  Reflect.deleteProperty(this, 'browser');
168
  this.emit('crippled');
 
169
  }
170
 
171
  async newPage() {
 
151
 
152
  @maxConcurrency(1)
153
  async healthCheck() {
154
+ this.pagePool.max += 1;
155
+ const healthyPage = await this.pagePool.acquire(3).catch((err) => {
156
+ this.logger.warn(`Health check failed`, { err: marshalErrorLike(err) });
157
  return null;
158
  });
159
+ this.pagePool.max -= 1;
160
 
161
  if (healthyPage) {
162
  this.pagePool.release(healthyPage);
163
  return;
164
  }
165
 
166
+ this.logger.warn(`Trying to clean up...`);
167
  await this.pagePool.clear();
168
  this.browser.process()?.kill('SIGKILL');
169
  Reflect.deleteProperty(this, 'browser');
170
  this.emit('crippled');
171
+ this.logger.warn(`Browser killed`);
172
  }
173
 
174
  async newPage() {