fix: finalizer and unhandled promise rejection

This commit is contained in:
yanlong.wang 2025-03-10 15:05:55 +08:00
parent eba1f9c0ec
commit df127d0207
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37
5 changed files with 14 additions and 10 deletions

8
package-lock.json generated
View File

@ -17,7 +17,7 @@
"axios": "^1.3.3",
"bcrypt": "^5.1.0",
"busboy": "^1.6.0",
"civkit": "^0.8.4-92aafc5",
"civkit": "^0.8.4-ef21ac9",
"core-js": "^3.37.1",
"cors": "^2.8.5",
"dayjs": "^1.11.9",
@ -3989,9 +3989,9 @@
}
},
"node_modules/civkit": {
"version": "0.8.4-92aafc5",
"resolved": "https://registry.npmjs.org/civkit/-/civkit-0.8.4-92aafc5.tgz",
"integrity": "sha512-Je5DTJs8H3fl3WYBbvKwqTzfUm5NuHt9WIrN3hJ5AHosQWGuyLrQf7N2lKo50aiTJdixEr3NDHqUwQ1KY59yoA==",
"version": "0.8.4-ef21ac9",
"resolved": "https://registry.npmjs.org/civkit/-/civkit-0.8.4-ef21ac9.tgz",
"integrity": "sha512-CAGzSIcXeBbYmhweTBqTqoroIpxI/dH87KhlT6MzokOiMpRcs02NJXM5V/KPbZ5hTqT9jii2xGd1CwsvTYZezg==",
"license": "AGPL",
"dependencies": {
"lodash": "^4.17.21",

View File

@ -26,7 +26,7 @@
"axios": "^1.3.3",
"bcrypt": "^5.1.0",
"busboy": "^1.6.0",
"civkit": "^0.8.4-92aafc5",
"civkit": "^0.8.4-ef21ac9",
"core-js": "^3.37.1",
"cors": "^2.8.5",
"dayjs": "^1.11.9",

View File

@ -53,7 +53,10 @@ export class BlackHoleDetector extends AsyncService {
if (this.strikes >= 3) {
this.logger.error(`BlackHole detected for ${this.strikes} strikes, last worked: ${Math.ceil(dt / 1000)}s ago, concurrentRequests: ${this.concurrentRequests}`);
this.emit('error', new Error(`BlackHole detected for ${this.strikes} strikes, last worked: ${Math.ceil(dt / 1000)}s ago, concurrentRequests: ${this.concurrentRequests}`));
process.nextTick(() => {
this.emit('error', new Error(`BlackHole detected for ${this.strikes} strikes, last worked: ${Math.ceil(dt / 1000)}s ago, concurrentRequests: ${this.concurrentRequests}`));
// process.exit(1);
});
}
}

View File

@ -25,6 +25,9 @@ export class FinalizerService extends AbstractFinalizerService {
super(...arguments);
}
override onUnhandledRejection(err: unknown, _triggeringPromise: Promise<unknown>): void {
this.logger.error(`Unhandled promise rejection in pid ${process.pid}`, { err });
}
}
const instance = container.resolve(FinalizerService);

View File

@ -1012,7 +1012,6 @@ export class PuppeteerControl extends AsyncService {
}
let nextSnapshotDeferred = Defer();
nextSnapshotDeferred.promise.catch(() => 'just dont crash anything');
const crippleListener = () => nextSnapshotDeferred.reject(new ServiceCrashedError({ message: `Browser crashed, try again` }));
this.once('crippled', crippleListener);
nextSnapshotDeferred.promise.finally(() => {
@ -1077,10 +1076,10 @@ export class PuppeteerControl extends AsyncService {
}
this.logger.warn(`Page ${sn}: Browsing of ${url} failed`, { err: marshalErrorLike(err) });
return Promise.reject(new AssertionFailureError({
return new AssertionFailureError({
message: `Failed to goto ${url}: ${err}`,
cause: err,
}));
});
}).then(async (stuff) => {
// This check is necessary because without snapshot, the condition of the page is unclear
// Calling evaluate directly may stall the process.
@ -1145,7 +1144,6 @@ export class PuppeteerControl extends AsyncService {
);
}
});
gotoPromise.catch(() => 'just dont crash anything');
let waitForPromise: Promise<any> | undefined;
if (options.waitForSelector) {
const t0 = Date.now();