From b9bd1ed83d857baa77e777e6f8b3d26bac9bd4c1 Mon Sep 17 00:00:00 2001 From: "Chris M. Vasseng" Date: Tue, 12 Nov 2024 14:19:50 +0100 Subject: [PATCH] Fix: faster exit on timeouts --- lib/pool.js | 6 ++++-- lib/server/error.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/pool.js b/lib/pool.js index 6a875a5e..65a05609 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -180,6 +180,7 @@ export const initPool = async (config) => { pool.on('destroySuccess', (eventId, resource) => { log(4, `[pool] Destroyed a worker with ID ${resource.id}.`); + resource.page = null; }); const initialResources = []; @@ -310,8 +311,9 @@ export const postWork = async (chart, options) => { if (result instanceof Error) { // TODO: If the export failed because puppeteer timed out, we need to force kill the worker so we get a new page. That needs to be handled better than this hack. if (result.message === 'Rasterization timeout') { - workerHandle.page.close(); - workerHandle.page = await newPage(); + // workerHandle.page.close(); + // workerHandle.page = await newPage(); + workerHandle.workCount = poolConfig.workLimit + 1; } throw new ExportError( diff --git a/lib/server/error.js b/lib/server/error.js index e7978c9e..eaeef9f9 100644 --- a/lib/server/error.js +++ b/lib/server/error.js @@ -33,7 +33,7 @@ const logErrorMiddleware = (error, req, res, next) => { const returnErrorMiddleware = (error, req, res, next) => { // Gather all requied information for the response const { statusCode: stCode, status, message, stack } = error; - const statusCode = stCode || status || 500; + const statusCode = stCode || status || 400; // Set and return response res.status(statusCode).json({ statusCode, message, stack });