diff --git a/backend/Dockerfile b/backend/Dockerfile index 775ef1a81..2d507448f 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -13,7 +13,8 @@ RUN npm ci COPY . /opt/app-root/src RUN apk upgrade --no-cache --available \ - && apk add --no-cache chromium-swiftshader nss freetype harfbuzz ca-certificates ttf-freefont ghostscript + && apk add --no-cache chromium-swiftshader nss freetype \ + harfbuzz ca-certificates ttf-freefont tini ghostscript ENV CHROME_BIN=/usr/bin/chromium-browser \ CHROME_PATH=/usr/lib/chromium/ \ @@ -25,4 +26,5 @@ RUN mkdir -p /tmp/npm \ && chmod -R 777 /tmp/npm EXPOSE 443 8080 -CMD ["npm", "start"] +ENTRYPOINT ["/sbin/tini", "--"] +CMD ["node", "--max-old-space-size=450", "./src/server.js"] diff --git a/backend/src/components/application.js b/backend/src/components/application.js index 5ae9522cb..e07edb417 100644 --- a/backend/src/components/application.js +++ b/backend/src/components/application.js @@ -450,12 +450,18 @@ async function printPdf(req, numOfRetries = 0) { ] }); //to debug locally add {headless: false, devtools: true} in options <-make sure they are boolean and not string + const browserProcess = browser.process(); + browserProcess + .on('exit', code => log.info(`printPdf :: browser process exited, status: ${code}`)); + browserProcess + .on('close', code => log.info(`printPdf :: browser process closed, status: ${code}`)); + try { log.info('printPdf :: starting new page'); const page = await browser.newPage(); + page.setDefaultTimeout(300000); //set navigation timeouts to 5 mins. So large organizations waiting to load do not throw error. await page.setRequestInterception(true); - await page.setDefaultTimeout(300000); //set navigation timeouts to 5 mins. So large organizations waiting to load do not throw error. page.on('request', (request) => { const headers = request.headers(); @@ -471,7 +477,6 @@ async function printPdf(req, numOfRetries = 0) { log.info('printPdf :: pdf buffer created starting compression'); const compressedPdfBuffer = await compress(pdfBuffer, {gsModulePath: process.env.GHOSTSCRIPT_PATH}); //this is set in dockerfile to fix ghostscript error on deploy log.info('printPdf :: compression completed for applicationId', req.params.applicationId); - await browser.close(); let payload; //if the body contains an application ID, the summary dec is for PCF. Else, it should be a change request. @@ -502,7 +507,6 @@ async function printPdf(req, numOfRetries = 0) { return payload; } catch (e) { log.error(e); - await browser.close(); if (numOfRetries >= 3) { log.info('printPdf :: maximum number of retries reached'); @@ -514,6 +518,8 @@ async function printPdf(req, numOfRetries = 0) { log.info(`printPdf :: retry count ${retryCount}`); await printPdf(req, retryCount); } + } finally { + await browser.close(); } }