alvarcarto / url-to-pdf-api

Web page PDF/PNG rendering done right. Self-hosted service for rendering receipts, invoices, or any content.
MIT License
7.03k stars 779 forks source link

Crash after 'read ECONNRESET' error #69

Closed Haerezis closed 6 years ago

Haerezis commented 6 years ago

Hi,

I get this error randomly when I try to generate a pdf from my local url-to-pdf.

What I get

The server crash with the following error : Error: read ECONNRESET at exports._errnoException (util.js:1018:11) at TCP.onread (net.js:568:26). curl print curl: (52) Empty reply from server

What I do

curl -o test_.pdf -XPOST -d@test-subject.html -H"content-type: text/html" http://localhost:9000/api/render\?emulateScreenMedia=false\&goto.waitUntil\=load

Solution?

This bug only happens AFTER the pdf generation, when browser.close() is called, but I don't know if this is caused by puppeteer closing its connexion to chrome, or the connexion to one of the assets of the page. Because this error happens after the pdf generation, I'm inclined to ignore it, and it can be done by adding a callback on process.on('uncaughtException', (error) => {}), but I'm not sure that's the correct thing to do, but for now it's the only solution I can provide.

The html file I use

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Test</title>
  <!-- Normalize or reset CSS with your favorite library -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.css">

  <!-- Load paper.css for happy printing -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/paper-css/0.2.3/paper.css">
  <style>
    @page { 
      size: A4; 
    }
    img {
      display: block;
      position: absolute;
    }

    img:nth-of-type(1) {
      left: 200px;
      top: 200px;
      transform: rotate(30deg);
    }
    img:nth-of-type(2) {
      left: 10%;
      top: 70%;
      transform: rotate(200deg);
    }
    img:nth-of-type(2) {
      float: right;
    }
  </style>
</head>
<body class="A4">
  <section class="sheet">
    <h1>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum, laboriosam!</h1>
    <p>Lorem ipsum dolor sit amet, <u>consectetur</u> adipisicing elit. <em>Officia</em> <strong>aspernatur sed</strong> <i>quis</i> veniam! Itaque fugiat voluptas rerum necessitatibus iste, <b>dolores id eligendi minus! <i>Velit <u>alias</u></i> quos</b> , deleniti optio quod numquam perspiciatis sequi. Hic autem omnis non ipsam odio. Sit nostrum officia, ea officiis corporis tempore ut illum minus placeat repellat similique natus facere iusto aperiam rerum magni inventore in vero error, quisquam nihil dolore culpa optio necessitatibus, dicta? Sit quos enim, id quidem ea amet voluptas vitae odit sequi, ex aliquid commodi illum aperiam odio suscipit reiciendis</p>
    <img src="https://placehold.it/400x400" alt="placeholder">
    <img src="https://placehold.it/400x400" alt="placeholder">
    <img src="https://placehold.it/400x400" alt="placeholder">
    <img src="https://placehold.it/400x400" alt="placeholder">
    <img src="https://placehold.it/400x400" alt="placeholder">
  </section>
  <section class="sheet">
    <h1>Such wow</h1>
    <h2>Such wow</h2>
    <h3>Such wow</h3>
    <h4>Such wow</h4>
    <h5>Such wow</h5>
    <h6>Such wow</h6>
    <p style="text-align: left">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima, tempora? Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestiae ipsa inventore laborum rem deserunt placeat, praesentium soluta exercitationem corporis at, voluptatibus id atque amet voluptate mollitia nam sunt nisi, excepturi facilis nemo! Maiores deserunt qui, quia soluta culpa accusantium distinctio numquam eaque asperiores maxime suscipit, iusto inventore. Adipisci, quasi corporis!</p>
    <p style="text-align: right">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima, tempora? Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laborum, suscipit? Officia rem dolorum, quisquam autem expedita ea odio aliquam dicta amet corporis voluptatum ipsam sequi ipsa accusantium enim molestiae nemo, qui, et odit quod corrupti ab? Odio, quisquam voluptatem aperiam totam illum repellendus temporibus harum dolores, laboriosam alias, doloremque et?</p>
    <p style="text-align: center">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima, tempora? Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente ipsam consectetur omnis ut repellendus, amet commodi minus fugit consequatur recusandae necessitatibus explicabo quasi nostrum eveniet dolores similique eligendi, expedita blanditiis doloremque nemo nobis. Sint aspernatur, mollitia expedita nulla est, rerum aliquam error. Provident saepe similique, dignissimos quia explicabo ab, nihil.</p>
    <p style="text-align: justify;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima, tempora? Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente ipsam consectetur omnis ut repellendus, amet commodi minus fugit consequatur recusandae necessitatibus explicabo quasi nostrum eveniet dolores similique eligendi, expedita blanditiis doloremque nemo nobis. Sint aspernatur, mollitia expedita nulla est, rerum aliquam error. Provident saepe similique, dignissimos quia explicabo ab, nihil.</p>
    <h1 style="transform: rotate(180deg);text-align: center;">WOOOOOOOOOOOOOOW</h1>
    <h1 style="transform: rotate(50deg);text-align: center;">AMAZING</h1>
    <h1 style="transform: rotate(80deg);text-align: center;">WOOOOOOOOOOOOOOW</h1>
    <h1 style="transform: rotate(300deg);text-align: center;">WOOOOOOOOOOOOOOW</h1>
    <h1 style="transform: rotate(260deg);text-align: center;">WOOOOOOOOOOOOOOW</h1>
    <h1 style="transform: rotate(120deg);text-align: center;">WOOOOOOOOOOOOOOW</h1>
    <h1 style="transform: rotate(190deg);text-align: center;">WOOOOOOOOOOOOOOW</h1>
  </section>

</body>
</html>
zys101 commented 6 years ago

I have this problem, too. now are you Solve the problem

zys101 commented 6 years ago

这个问题 已经解决了 你可以使用下面的命令:

npm install ws@3.3.2 --save-dev --save-exact @Haerezis

https://github.com/ionic-team/ionic-cli/issues/2922

Haerezis commented 6 years ago

Thanks. After digging, it seems like there were already a issue for this problem : https://github.com/alvarcarto/url-to-pdf-api/issues/57.

The problem seems related to ws and puppeteer.

So I'm closing this issue.