Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close renderer headless browser in finally block. #8980

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions components/renderer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ 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")
// This endpoint is used by the Docker health check command (that in turn uses src/healthcheck.cjs) to report the
// health of the renderer component
const healthy = browser.connected ?? false
res.status(healthy ? 200 : 503).send(healthy ? "OK" : "Chromium not connected")
fniessink marked this conversation as resolved.
Show resolved Hide resolved
})

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 +41,26 @@ app.get("/api/render", async (req, res) => {
}
});
console.log(`URL ${url}: PDF created`);
await browser.close();
fniessink marked this conversation as resolved.
Show resolved Hide resolved
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).
- Closing the Chromium browser in the renderer component after creating a PDF would not stop all browser child processes. Fixed by starting Chromium only once and reusing, instead of starting a new browser for each render. Fixes [#8979](https://github.com/ICTU/quality-time/issues/8979).

### Added

Expand Down