Skip to content

Commit

Permalink
Prevent zombie process in renderer.
Browse files Browse the repository at this point in the history
Prevent zombie browser processes by starting Chromium only once and opening and closing a new page for each render.

Closes #8979.
  • Loading branch information
fniessink committed Jun 14, 2024
1 parent ba8c7ae commit fa423ed
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
30 changes: 19 additions & 11 deletions components/renderer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@ const app = express();
const RENDERER_PORT = process.env.RENDERER_PORT || 9000;
const PROXY = `${process.env.PROXY_HOST || 'www'}:${process.env.PROXY_PORT || 80}`;
const PROTOCOL = process.env.PROXY_PROTOCOL || 'http';
let browser

app.get("/api/health", async (_req, res) => {
res.status(200).send("OK")
const healthy = browser.connected ?? false
res.status(healthy ? 200 : 503).send(healthy ? "OK" : "Chromium not connected")
})

app.get("/api/render", async (req, res) => {
let webPage
try {
const url = sanitizeUrl(`${PROTOCOL}://${PROXY}/${req.query.path}`);
const browser = await puppeteer.launch({
defaultViewport: { width: 1500, height: 1000 },
args: ['--disable-dev-shm-usage', '--no-sandbox'],
// Opt in to new Chrome headless implementation, see https://developer.chrome.com/articles/new-headless/:
headless: "new",
});
const webPage = await browser.newPage();
webPage = await browser.newPage();
await webPage.goto(url, {
waitUntil: "networkidle2",
timeout: 60000
Expand All @@ -42,15 +39,26 @@ app.get("/api/render", async (req, res) => {
}
});
console.log(`URL ${url}: PDF created`);
await browser.close();
res.contentType("application/pdf");
res.send(pdf);
} catch (error) {
console.error(error)
res.sendStatus(500)
} finally {
await webPage.close()
}
})

app.listen(RENDERER_PORT, () => {
console.log(`Renderer started on port ${RENDERER_PORT}. Using proxy ${PROXY}`);
app.listen(RENDERER_PORT, async () => {
try {
browser = await puppeteer.launch({
defaultViewport: { width: 1500, height: 1000 },
args: ['--disable-dev-shm-usage', '--no-sandbox'],
// Opt in to new Chrome headless implementation, see https://developer.chrome.com/articles/new-headless/:
headless: "new",
})
console.log(`Renderer started on port ${RENDERER_PORT}. Using proxy ${PROXY}`);
} catch (error) {
console.log(error)
}
});
3 changes: 2 additions & 1 deletion docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ If your currently installed *Quality-time* version is not v5.13.0, please first
### Fixed

- In the dropdown of the "Add metric" button, keep the two checkboxes next to each other regardless of the width of the menu. Fixes [#8745](https://github.com/ICTU/quality-time/issues/8745).
- The icon of the trend graph tab would not be shown. Closes [#8822](https://github.com/ICTU/quality-time/issues/8822).
- The icon of the trend graph tab would not be shown. Fixes [#8822](https://github.com/ICTU/quality-time/issues/8822).
- Prevent zombie browser processes in the renderer component when creating PDF fails by closing the browser regardless of whether generating the PDF succeeds or not. Fixes [#8979](https://github.com/ICTU/quality-time/issues/8979).

### Added

Expand Down

0 comments on commit fa423ed

Please sign in to comment.