Skip to content

Commit fdd041c

Browse files
committed
On unexpected worker exit, shut down entire pool (gracefully)
1 parent afcaaed commit fdd041c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/main.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,12 +1282,24 @@ export function _runTaskList(
12821282
workerPool._workers.push(worker);
12831283
const remove = () => {
12841284
if (continuous && workerPool._active && !workerPool._shuttingDown) {
1285+
// TODO: user should choose how to handle this, maybe via a middleware:
1286+
// - graceful shutdown (implemented)
1287+
// - forceful shutdown (probably best after a delay)
1288+
// - boot up a replacement worker
1289+
/* middleware.run("poolWorkerPrematureExit", {}, () => { */
12851290
logger.error(
12861291
`Worker exited, but pool is in continuous mode, is active, and is not shutting down... Did something go wrong?`,
12871292
);
1293+
_finErrors.push(
1294+
new Error(`Worker ${worker.workerId} exited unexpectedly`),
1295+
);
1296+
workerPool.gracefulShutdown(
1297+
"Something went wrong, one of the workers exited prematurely. Shutting down.",
1298+
);
1299+
/* }) */
12881300
}
12891301
workerPool._workers.splice(workerPool._workers.indexOf(worker), 1);
1290-
if (!continuous && workerPool._workers.length === 0) {
1302+
if (workerPool._workers.length === 0) {
12911303
if (!workerPool._shuttingDown) {
12921304
workerPool.gracefulShutdown(
12931305
"'Run once' mode processed all available jobs and is now exiting",

0 commit comments

Comments
 (0)