title: Memory leak in express / puppeeter node app?
body: <p>I'm new to express / node and trying to build an api endpoint to retrieve html from websites :</p>
  <pre><code>// load express
  const express = require('express');
  
  // get app &amp; port
  const app = express();
  const port = process.env.PORT || 3000 ;
  
  // get current url parameter and process
  app.get('/', function(req, res) {
  
  const url = req.query.url;
  const puppeteer = require('puppeteer') ;
  
  (async () =&gt; {
  
      try {
  
          var browser = await puppeteer.launch({
              headless: true,
              devtools: false,
              ignoreHTTPSErrors: true,
              userDataDir: 'tmp' ,
              args: [
                  '--no-sandbox',
                  '--single-process',
                  '--no-zygote',
                  '--disable-setuid-sandbox',
                  '--disable-gpu'
              ]
          });
  
  
         // build a new page
          const page = await browser.newPage()
  
          // set options
          await page.setViewport({width: 800, height: 600})
          await page.setDefaultNavigationTimeout( 30000 ) ;
  
          // start time
          var start = Date.now();
  
          // explore url
          try {
  
              // goto page
              const response = await page.goto(url, { waitUntil: 'load'} );
  
              // get http response code
              const response_status = response == null ? 0 : response.status() ;
  
              // get html
              const data = await page.evaluate(() =&gt; document.querySelector('*').outerHTML);
  
              // send result
              res.send({
                  'success' : true,
                  'url': url,
                  'http_code' : response_status ,
                  'time' :  Date.now() - start,
                  'data' : data
              });
          }
          // catch errors
          catch( err ) {
  
              // get page error
              const page_error = err.toString()
  
              // send error
              res.send({
                  'success' : false,
                  'url': url,
                  'error' : page_error,
                  'time' :  Date.now() - start
              });
          }
  
      } catch (err) {
  
          // send error
          res.send({
              'success' : false,
              'url': url,
              'error' : err.toString(),
              'time' :  Date.now() - start
          });
  
      } finally {
  
          await browser.close();
      }
  
  })();
  
  })
  
  
  // start app
  app.listen(port);
  </code></pre>
  <p>When using the endpoint at a rate of ~1 request per second, pm2 monitoring shows an increasing http latency.</p>
  <p>First minute :</p>
  <p><a href="https://i.stack.imgur.com/hrIQZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hrIQZ.png" alt="enter image description here" /></a></p>
  <p>After ~10 minutes :</p>
  <p><a href="https://i.stack.imgur.com/QjcPZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QjcPZ.png" alt="enter image description here" /></a></p>
  <p>The memory used seem to increase too from 140M to more (500M after few minutes):</p>
  <p><a href="https://i.stack.imgur.com/it2jS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/it2jS.png" alt="enter image description here" /></a></p>
  <p>Not sure where the memory leak could come from.</p>