title: Puppeteer cluster.close() "crashes" after calling cluster.queue()
body: <p>Long story short, I've made an app for web scraping and in order for it to be able to simultaneously run more then 1 process at a time (more than 1 Chromium opened), i used puppeteer-cluster. I've got it to run several processes at once, but the cluster won't stop afterwards, it permanently runs. Along the way, I've encountered the following error (1)</p>
  <pre><code>await cluster.close(); // Gives the following error -&gt; cluster.close is not a function (1)
  </code></pre>
  <p>If i use it like this (2)</p>
  <pre><code>(await cluster).close(); // This returns no error (2)
  </code></pre>
  <p>Anywho, the main problem is that when the code gets to the line where cluster gets closed (at the end of the code, check code below), it freezes there. Won't return any error, as i tried catching it, but at the same time it won't crash either.</p>
  <pre><code>const puppeteer = require('puppeteer');
  const { Cluster }  = require('puppeteer-cluster/');
  
  function delay(time) {
   return new Promise(function(resolve) { 
     setTimeout(resolve, time)
   });
  }
  
  
  (async () =&gt; {
  
    const cluster = Cluster.launch({
      concurrency: Cluster.CONCURRENCY_BROWSER,
      maxConcurrency: 2,
    });
  
    const test = async () =&gt; {
  
      const user = process.argv[2];
      const pass = process.argv[3];
      const smis = process.argv[4];
      const nrinreg = process.argv[5];
  
  
  
      const browser = await puppeteer.launch({headless: false, defaultViewport: null, args:['--start-fullscreen']}); // you can also use '--start-fullscreen']});
      const page = await browser.newPage();
      //await page.setViewport({width: 1200, height: 900});
      await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: './'+smis+''}).catch(e =&gt; {});
      await page.goto('https://aplicatii2014.smis.fonduri-ue.ro/smis2014app/').catch(e =&gt; {});
      await delay(2000);
      // await page.waitFor(3000);
  
      //scriere credentiale pt elementele de tip HTML user&amp;parola
      await page.type('#j_idt38 &gt; .step-content &gt; .step-pane &gt; .col-md-12 &gt; .form-group &gt; input[name=&quot;j_idt38:utilizator&quot;]', user).catch(e =&gt; {});
      await delay(1000);
      await page.type('#j_idt38 &gt; .step-content &gt; .step-pane &gt; .col-md-12 &gt; .form-group &gt; input[name=&quot;j_idt38:pass&quot;]', pass).catch(e =&gt; {});
      await delay(1000);
      page.click('#j_idt38 &gt; .actions &gt; a').catch(e =&gt; {});
  
      await delay(2000);
  
      page.click('#idPanelGroup &gt; #headerPanel &gt; div &gt; #j_idt18 &gt; tbody &gt; tr &gt; #topMenuCell &gt; #j_idt22').catch(e =&gt; {});
      await delay(2000);
      await page.type('#dialogCereriFinantare &gt; .ui-dialog-content &gt; #formCereriFinantare &gt; table &gt; tbody &gt; tr &gt; td &gt; input[id=&quot;formCereriFinantare:idSmisAll&quot;]', smis).catch(e =&gt; {});
      await delay(1000);
      page.click('#dialogCereriFinantare &gt; .ui-dialog-content &gt; #formCereriFinantare &gt; table &gt; tbody &gt; tr &gt; td &gt; a[id=&quot;formCereriFinantare:commandBtnSearch&quot;]').catch(e =&gt; {});
      await delay(1000);
      page.click('span.ui-chkbox-icon.ui-icon.ui-icon-blank.ui-c').catch(e =&gt; {});
      await delay(1000);
      await page.type('#dialogAcordConfidentialitate &gt; .ui-dialog-content &gt; #formAcordConfidentialitate &gt; div[id=&quot;formAcordConfidentialitate:j_idt167&quot;] &gt; .ui-scrollpanel-container &gt; .ui-scrollpanel-content &gt; .col-md-12 &gt; .row &gt; .col-md-3 &gt; input[id=&quot;formAcordConfidentialitate:CNP&quot;]', pass).catch(e =&gt; {});
      await delay(1000);
      page.click('#dialogAcordConfidentialitate &gt; .ui-dialog-content &gt; #formAcordConfidentialitate &gt; div[id=&quot;formAcordConfidentialitate:j_idt167&quot;] &gt; .ui-scrollpanel-container &gt; .ui-scrollpanel-content &gt; .col-md-12 &gt; .row &gt; a[id=&quot;formAcordConfidentialitate:btnConfirmContent&quot;]').catch(e =&gt; {});
      await delay(1000);
      page.click('#dialogCereriFinantare &gt; .ui-dialog-content &gt; #formCereriFinantare &gt; div &gt; div &gt; a &gt; .ui-icon-seek-end').catch(e =&gt; {});
      await delay(2000);
  
      const doc_details = await page.evaluate(() =&gt; {
      //Extract each doc's basic details
      let table = document.querySelector('#dialogCereriFinantare &gt; .ui-dialog-content &gt; #formCereriFinantare &gt; div[id=&quot;formCereriFinantare:tableCereriFinantare&quot;] &gt; .ui-datatable-tablewrapper &gt; table &gt; tbody');
      let doc_panels = Array.from(table.children); 
      // Loop through each doc and get their details 
      let doc_info = doc_panels.map(doc_panel =&gt; {
        let codsmis = doc_panel.querySelector(&quot;tr &gt; td:nth-child(1)&quot;).textContent;
        let titlu = doc_panel.querySelector(&quot;tr &gt; td:nth-child(2)&quot;).textContent;
        let versiune = doc_panel.querySelector(&quot;tr &gt; td:nth-child(3)&quot;).textContent;
        let contractare = doc_panel.querySelector(&quot;tr &gt; td:nth-child(4)&quot;).textContent;
  
        return { versiune, contractare };
      });
  
  
      return doc_info;
      });
  
  
      doc_details.sort((a, b) =&gt; (parseInt(a.versiune) &lt; parseInt(b.versiune) ? 1 : -1));
      let res = new Array();
      res = doc_details.filter(a =&gt; a.contractare.length &gt; 0);
  
  
    /**
     * Get first elem from a array
     * // [...res].shift()
     */
     const [first] = res;
    /**
     * If no element exist 
     */
  
     if (first === null) {
      page.click('#dialogCereriFinantare &gt; .ui-dialog-content &gt; #formCereriFinantare &gt; div &gt; div &gt; a &gt; .ui-icon-seek-prev').catch(e =&gt; { });
    }
    else {
  
      let version = first[&quot;versiune&quot;];
  
      await delay(1000);
  
      const example = await page.$('#dialogCereriFinantare &gt; .ui-dialog-titlebar');
      const bounding_box = await example.boundingBox();
  
      await page.mouse.move(bounding_box.x + bounding_box.width / 2, bounding_box.y + bounding_box.height / 2);
      await page.mouse.down();
      await page.mouse.move(126, 19);
      await page.mouse.up();
      
      await delay(1000);
      await page.waitForXPath(&quot;//tr/td[3][contains(., '&quot;+ version +&quot;')]&quot;);  
      const [projects] = await page.$x(&quot;//tr/td[3][contains(., '&quot;+ version +&quot;')]&quot;);
      projects.click().catch(e =&gt; {});
  
      await delay(2000);
      await page.goto(&quot;https://aplicatii2014.smis.fonduri-ue.ro/smis2014app/faces/pages/comunicare.xhtml&quot;).catch(e =&gt; {});
      await delay(2000);
  
      await page.evaluate(() =&gt; {
        document.querySelector('#j_idt68 &gt; div &gt; #idPanelContent &gt; #j_idt140 &gt; #j_idt140_content &gt; #j_idt142 &gt; div &gt; .ui-datatable-tablewrapper &gt; table &gt; tbody').scrollIntoView();
      }).catch(e =&gt; {});
  
  
      await delay(2000).catch(e =&gt; {});
      
      const [com] = await page.$x(&quot;//tr/td[1][contains(., '37114')]&quot;).catch(e =&gt; {});
  
      if (com){
        com.click().catch(e =&gt; {});
      }
      else
      {
        let [com2] = await page.$x(&quot;//tr/td[1][contains(., '&quot;+ nrinreg +&quot;')]&quot;);
        do{
          page.click('#j_idt68 &gt; div &gt; #idPanelContent &gt; #j_idt140 &gt; #j_idt140_content &gt; #j_idt142 &gt; div &gt; div[id=&quot;j_idt142:idComunicareTable_paginator_bottom&quot;] &gt; .ui-paginator-next').catch(e =&gt; {});
          await delay(2000).catch(e =&gt; {});
          let [com2] = await page.$x(&quot;//tr/td[1][contains(., '&quot;+ nrinreg +&quot;')]&quot;).catch(e =&gt; {});
          if (com2){
            break;
          }
        }
        while(!com2);
  
        
        let [com3] = await page.$x(&quot;//tr/td[1][contains(., '&quot;+ nrinreg +&quot;')]&quot;).catch(e =&gt; {});
        com3.click().catch(e =&gt; {});
  
        await delay(2000).catch(e =&gt; {});
  
        await page.evaluate(() =&gt; {
          document.querySelector('#j_idt68 &gt; div &gt; #idPanelContent &gt; #j_idt140 &gt; div &gt; #idDetaliicomunicare').scrollIntoView();
        }).catch(e =&gt; {});
  
        await delay(2000).catch(e =&gt; {});
      }
  
      await delay(2000);
  
      const listadownload = await page.$$('#j_idt68 &gt; div &gt; #idPanelContent &gt; div &gt; div &gt; #idDetaliicomunicare &gt; div &gt; div &gt; div &gt; ul &gt; li &gt; .ui-treenode-children  &gt; li &gt; span');
  
      for (let iteminlistadownload of listadownload){
        await iteminlistadownload.click({button: 'right',}).catch(e =&gt; {});
        await delay(2000);
        let [viz] = await page.$x('//*[@id=&quot;idDetaliicomunicare:j_idt163&quot;]/ul/li/a').catch(e =&gt; {});
        viz.click().catch(e =&gt; {});
        await delay(2000);
      }
  
  
    }
  
   
    await delay(3000);
    await browser.close();
    
  };
  
  
    
    (await cluster).queue(test);
    
    
    (await cluster).idle();
  
    
    (await cluster).close();
  
    
  
  
  })();
  
  
  </code></pre>
  <p>I have been scraping the internet for a solution, looking for fixes on GitHub and nothing seems to work. What is it that I'm doing wrong that simply just won't terminate the process?
  PS : I added the whole code in hopes of it being relevant.</p>