Spaces:
Build error
Build error
fix: finalizer and unhandled promise rejection
Browse files- package-lock.json +4 -4
- package.json +1 -1
- src/services/blackhole-detector.ts +4 -1
- src/services/finalizer.ts +3 -0
- src/services/puppeteer.ts +2 -4
package-lock.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
| 17 |
"axios": "^1.3.3",
|
| 18 |
"bcrypt": "^5.1.0",
|
| 19 |
"busboy": "^1.6.0",
|
| 20 |
-
"civkit": "^0.8.4-
|
| 21 |
"core-js": "^3.37.1",
|
| 22 |
"cors": "^2.8.5",
|
| 23 |
"dayjs": "^1.11.9",
|
|
@@ -3989,9 +3989,9 @@
|
|
| 3989 |
}
|
| 3990 |
},
|
| 3991 |
"node_modules/civkit": {
|
| 3992 |
-
"version": "0.8.4-
|
| 3993 |
-
"resolved": "https://registry.npmjs.org/civkit/-/civkit-0.8.4-
|
| 3994 |
-
"integrity": "sha512-
|
| 3995 |
"license": "AGPL",
|
| 3996 |
"dependencies": {
|
| 3997 |
"lodash": "^4.17.21",
|
|
|
|
| 17 |
"axios": "^1.3.3",
|
| 18 |
"bcrypt": "^5.1.0",
|
| 19 |
"busboy": "^1.6.0",
|
| 20 |
+
"civkit": "^0.8.4-ef21ac9",
|
| 21 |
"core-js": "^3.37.1",
|
| 22 |
"cors": "^2.8.5",
|
| 23 |
"dayjs": "^1.11.9",
|
|
|
|
| 3989 |
}
|
| 3990 |
},
|
| 3991 |
"node_modules/civkit": {
|
| 3992 |
+
"version": "0.8.4-ef21ac9",
|
| 3993 |
+
"resolved": "https://registry.npmjs.org/civkit/-/civkit-0.8.4-ef21ac9.tgz",
|
| 3994 |
+
"integrity": "sha512-CAGzSIcXeBbYmhweTBqTqoroIpxI/dH87KhlT6MzokOiMpRcs02NJXM5V/KPbZ5hTqT9jii2xGd1CwsvTYZezg==",
|
| 3995 |
"license": "AGPL",
|
| 3996 |
"dependencies": {
|
| 3997 |
"lodash": "^4.17.21",
|
package.json
CHANGED
|
@@ -26,7 +26,7 @@
|
|
| 26 |
"axios": "^1.3.3",
|
| 27 |
"bcrypt": "^5.1.0",
|
| 28 |
"busboy": "^1.6.0",
|
| 29 |
-
"civkit": "^0.8.4-
|
| 30 |
"core-js": "^3.37.1",
|
| 31 |
"cors": "^2.8.5",
|
| 32 |
"dayjs": "^1.11.9",
|
|
|
|
| 26 |
"axios": "^1.3.3",
|
| 27 |
"bcrypt": "^5.1.0",
|
| 28 |
"busboy": "^1.6.0",
|
| 29 |
+
"civkit": "^0.8.4-ef21ac9",
|
| 30 |
"core-js": "^3.37.1",
|
| 31 |
"cors": "^2.8.5",
|
| 32 |
"dayjs": "^1.11.9",
|
src/services/blackhole-detector.ts
CHANGED
|
@@ -53,7 +53,10 @@ export class BlackHoleDetector extends AsyncService {
|
|
| 53 |
|
| 54 |
if (this.strikes >= 3) {
|
| 55 |
this.logger.error(`BlackHole detected for ${this.strikes} strikes, last worked: ${Math.ceil(dt / 1000)}s ago, concurrentRequests: ${this.concurrentRequests}`);
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
| 57 |
}
|
| 58 |
}
|
| 59 |
|
|
|
|
| 53 |
|
| 54 |
if (this.strikes >= 3) {
|
| 55 |
this.logger.error(`BlackHole detected for ${this.strikes} strikes, last worked: ${Math.ceil(dt / 1000)}s ago, concurrentRequests: ${this.concurrentRequests}`);
|
| 56 |
+
process.nextTick(() => {
|
| 57 |
+
this.emit('error', new Error(`BlackHole detected for ${this.strikes} strikes, last worked: ${Math.ceil(dt / 1000)}s ago, concurrentRequests: ${this.concurrentRequests}`));
|
| 58 |
+
// process.exit(1);
|
| 59 |
+
});
|
| 60 |
}
|
| 61 |
}
|
| 62 |
|
src/services/finalizer.ts
CHANGED
|
@@ -25,6 +25,9 @@ export class FinalizerService extends AbstractFinalizerService {
|
|
| 25 |
super(...arguments);
|
| 26 |
}
|
| 27 |
|
|
|
|
|
|
|
|
|
|
| 28 |
}
|
| 29 |
|
| 30 |
const instance = container.resolve(FinalizerService);
|
|
|
|
| 25 |
super(...arguments);
|
| 26 |
}
|
| 27 |
|
| 28 |
+
override onUnhandledRejection(err: unknown, _triggeringPromise: Promise<unknown>): void {
|
| 29 |
+
this.logger.error(`Unhandled promise rejection in pid ${process.pid}`, { err });
|
| 30 |
+
}
|
| 31 |
}
|
| 32 |
|
| 33 |
const instance = container.resolve(FinalizerService);
|
src/services/puppeteer.ts
CHANGED
|
@@ -1012,7 +1012,6 @@ export class PuppeteerControl extends AsyncService {
|
|
| 1012 |
}
|
| 1013 |
|
| 1014 |
let nextSnapshotDeferred = Defer();
|
| 1015 |
-
nextSnapshotDeferred.promise.catch(() => 'just dont crash anything');
|
| 1016 |
const crippleListener = () => nextSnapshotDeferred.reject(new ServiceCrashedError({ message: `Browser crashed, try again` }));
|
| 1017 |
this.once('crippled', crippleListener);
|
| 1018 |
nextSnapshotDeferred.promise.finally(() => {
|
|
@@ -1077,10 +1076,10 @@ export class PuppeteerControl extends AsyncService {
|
|
| 1077 |
}
|
| 1078 |
|
| 1079 |
this.logger.warn(`Page ${sn}: Browsing of ${url} failed`, { err: marshalErrorLike(err) });
|
| 1080 |
-
return
|
| 1081 |
message: `Failed to goto ${url}: ${err}`,
|
| 1082 |
cause: err,
|
| 1083 |
-
})
|
| 1084 |
}).then(async (stuff) => {
|
| 1085 |
// This check is necessary because without snapshot, the condition of the page is unclear
|
| 1086 |
// Calling evaluate directly may stall the process.
|
|
@@ -1145,7 +1144,6 @@ export class PuppeteerControl extends AsyncService {
|
|
| 1145 |
);
|
| 1146 |
}
|
| 1147 |
});
|
| 1148 |
-
gotoPromise.catch(() => 'just dont crash anything');
|
| 1149 |
let waitForPromise: Promise<any> | undefined;
|
| 1150 |
if (options.waitForSelector) {
|
| 1151 |
const t0 = Date.now();
|
|
|
|
| 1012 |
}
|
| 1013 |
|
| 1014 |
let nextSnapshotDeferred = Defer();
|
|
|
|
| 1015 |
const crippleListener = () => nextSnapshotDeferred.reject(new ServiceCrashedError({ message: `Browser crashed, try again` }));
|
| 1016 |
this.once('crippled', crippleListener);
|
| 1017 |
nextSnapshotDeferred.promise.finally(() => {
|
|
|
|
| 1076 |
}
|
| 1077 |
|
| 1078 |
this.logger.warn(`Page ${sn}: Browsing of ${url} failed`, { err: marshalErrorLike(err) });
|
| 1079 |
+
return new AssertionFailureError({
|
| 1080 |
message: `Failed to goto ${url}: ${err}`,
|
| 1081 |
cause: err,
|
| 1082 |
+
});
|
| 1083 |
}).then(async (stuff) => {
|
| 1084 |
// This check is necessary because without snapshot, the condition of the page is unclear
|
| 1085 |
// Calling evaluate directly may stall the process.
|
|
|
|
| 1144 |
);
|
| 1145 |
}
|
| 1146 |
});
|
|
|
|
| 1147 |
let waitForPromise: Promise<any> | undefined;
|
| 1148 |
if (options.waitForSelector) {
|
| 1149 |
const t0 = Date.now();
|