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

[BUG] Calling _exit(1). Core file will not be generated. - Protocol error (Page.printToPDF): Target closed. #169

Closed
citak opened this issue Oct 20, 2020 · 6 comments
Assignees
Labels
duplicate This issue or pull request already exists wontfix This will not be worked on

Comments

@citak
Copy link

citak commented Oct 20, 2020

Environment

  • chrome-aws-lambda Version: 5.3.1
  • puppeteer / puppeteer-core Version: 5.3.x
  • OS: Mac
  • Node.js Version: 12.x
  • Lambda / GCF Runtime: nodejs12.x

Expected Behavior

Pdf should successfully be generated

Current Behavior

Protocol error (Page.printToPDF): Target closed.
Dumpio output: Calling _exit(1). Core file will not be generated.
I don't see any memory or space issues.

Steps to Reproduce

const chromium = require('chrome-aws-lambda');

exports.handler = async (event, context, callback) => {
  let result = null;
  let browser = null;

  try {
    browser = await chromium.puppeteer.launch({
      args: chromium.args,
      defaultViewport: chromium.defaultViewport,
      executablePath: await chromium.executablePath,
      headless: chromium.headless,
      ignoreHTTPSErrors: true,
    });

    let page = await browser.newPage();

    await page.goto( 'https://www.linkpicture.com/q/LPic5f8efc8e8c8391884650102.png');

    const config = {
        "path":"/tmp/test.pdf",
        "printBackground": true,
        "margin": "none"
    };
        await page.pdf(config);
  } catch (error) {
    return callback(error);
  } finally {
    if (browser !== null) {
      await browser.close();
    }
  }

  return callback(null, result);
};

Possible Solution

I tried to pass different flags, clearing space, upping memory nothing has worked so far. I did go through previous issues but couldn't find anything an exact issue. I found an issue where lambda runs out of memory or space but I checked thats not the case here. This is the image that fails: https://linkpicture.com/q/LPic5f8efc8e8c8391884650102.png

@citak citak added the bug Something isn't working label Oct 20, 2020
@QAnders
Copy link

QAnders commented Nov 16, 2020

I'm too am seeing this same error Protocol error (IO.read): Target closed. on a locally generated HTML which I am generating using PUG...
It only happens sporadically for me...

Logging out what's happening in /node_modules/puppeteer-core/lib/Connection.js:182:56 locally gives:

send(); Page.printToPDF {
  transferMode: 'ReturnAsStream',
  landscape: false,
  displayHeaderFooter: false,
  headerTemplate: '',
  footerTemplate: '',
  printBackground: true,
  scale: 1,
  paperWidth: 8.27,
  paperHeight: 11.7,
  marginTop: 0.39375,
  marginBottom: 0.39375,
  marginLeft: 0.39375,
  marginRight: 0.39375,
  pageRanges: '',
  preferCSSPageSize: false
}
send(); IO.read { handle: '1' }
send(); IO.read { handle: '1' }

The Page.printToPDF works fine, the first IO.read also is working while the second IO.read throws the error...

I can add that on AWS in Lambda I don't see this very often but locally it happens often and seems to be "time" related. E.g. it works fine ones, then fails if I try again soon after but if I wait e.g. 5 minutes it works again.
There are no processes (ps -ef) hanging and no other node or something running.

@QAnders
Copy link

QAnders commented Nov 17, 2020

Solved for me (I think)... this seems to stem from external references (CSS and FONT) in the PUG template.

I added a "waitUntil" as:

    // waitUntil is a bit tricky but seems 'domcontentloaded' is the safest as it will
    // wait until the HTML page DOM object has loaded completely.
    // networkidle0: comes handy for SPAs that load resources with fetch requests.
    // networkidle2: comes handy for pages that do long-polling or any other side activity.

    await page.setContent(html, { waitUntil: 'domcontentloaded' });

Now I can run it both in AWS and locally without issues!

@citak
Copy link
Author

citak commented Nov 18, 2020

I tried with all waitUntil options but nothing seems to work for me. Here is the output I'm getting.

`cklist instead.

DevTools listening on ws://127.0.0.1:36019/devtools/browser/
Received signal 6
#0 0x55b869dc6ab9 (/tmp/chromium+0x4ad4ab8)
#1 0x55b869d4a393 (/tmp/chromium+0x4a58392)
#2 0x55b869dc665b (/tmp/chromium+0x4ad465a)
#3 0x7fa6423497e0 (/usr/lib64/libpthread-2.26.so+0x117df)
#4 0x7fa641626b20 __GI_raise
#5 0x7fa641627fc8 __GI_abort
#6 0x55b869d75bda (/tmp/chromium+0x4a83bd9)
#7 0x55b869d75bf9 (/tmp/chromium+0x4a83bf8)
#8 0x55b869d75be9 (/tmp/chromium+0x4a83be8)
#9 0x55b869d5d4a7 (/tmp/chromium+0x4a6b4a6)
#10 0x55b86a2af3e3 (/tmp/chromium+0x4fbd3e2)
#11 0x55b867fccbb8 (/tmp/chromium+0x2cdabb7)
#12 0x55b8680e142f (/tmp/chromium+0x2def42e)
#13 0x55b8680e15c4 (/tmp/chromium+0x2def5c3)
#14 0x55b8680dfc0a (/tmp/chromium+0x2dedc09)
#15 0x55b86a4c14d5 (/tmp/chromium+0x51cf4d4)
#16 0x55b86a4c2356 (/tmp/chromium+0x51d0355)
#17 0x55b86a4bbb40 (/tmp/chromium+0x51c9b3f)
#18 0x55b86a4ba270 (/tmp/chromium+0x51c826f)
#19 0x55b867ff0868 (/tmp/chromium+0x2cfe867)
#20 0x55b867fed398 (/tmp/chromium+0x2cfb397)
#21 0x55b86aa59320 (/tmp/chromium+0x576731f)
#22 0x55b86aa5c168 (/tmp/chromium+0x576a167)
#23 0x55b86aa5d2c1 (/tmp/chromium+0x576b2c0)
#24 0x55b86aa5c0a4 (/tmp/chromium+0x576a0a3)
#25 0x55b86aa5d2c1 (/tmp/chromium+0x576b2c0)
#26 0x55b86aa5c0a4 (/tmp/chromium+0x576a0a3)
#27 0x55b86aa5d2c1 (/tmp/chromium+0x576b2c0)
#28 0x55b86aa5c0a4 (/tmp/chromium+0x576a0a3)
#29 0x55b86aa7426b (/tmp/chromium+0x578226a)
#30 0x55b86b4cf5d9 (/tmp/chromium+0x61dd5d8)
#31 0x55b86b4cd096 (/tmp/chromium+0x61db095)
#32 0x55b86b4cccb7 (/tmp/chromium+0x61dacb6)
#33 0x55b86b4cca7e (/tmp/chromium+0x61daa7d)
#34 0x55b86b4cca43 (/tmp/chromium+0x61daa42)
#35 0x55b86b4cb1c3 (/tmp/chromium+0x61d91c2)
#36 0x55b86b4cb4a7 (/tmp/chromium+0x61d94a6)
#37 0x55b86909668a (/tmp/chromium+0x3da4689)
#38 0x55b86a5f19c6 (/tmp/chromium+0x52ff9c5)
#39 0x55b86a5f4809 (/tmp/chromium+0x5302808)
#40 0x55b86a61d815 (/tmp/chromium+0x532b814)
#41 0x55b86a61b447 (/tmp/chromium+0x5329446)
#42 0x55b869d8d6c6 (/tmp/chromium+0x4a9b6c5)
#43 0x55b869d9bf69 (/tmp/chromium+0x4aa9f68)
#44 0x55b869d8d6c6 (/tmp/chromium+0x4a9b6c5)
#45 0x55b869d9da0d (/tmp/chromium+0x4aaba0c)
#46 0x55b869d9d708 (/tmp/chromium+0x4aab707)
#47 0x55b869d5fdfa (/tmp/chromium+0x4a6ddf9)
#48 0x55b869d9e02d (/tmp/chromium+0x4aac02c)
#49 0x55b869d792ce (/tmp/chromium+0x4a872cd)
#50 0x55b869db5627 (/tmp/chromium+0x4ac3626)
#51 0x55b869dd623e (/tmp/chromium+0x4ae423d)
#52 0x7fa64233f40b start_thread
#53 0x7fa6416dfeef __GI___clone
r8: 0000000000000000 r9: 00007fa631ab1120 r10: 0000000000000008 r11: 0000000000000246
r12: 000032dd49194ee0 r13: 00007fa631ab13f8 r14: 00000000148b03a0 r15: 00007fa631ab1400
di: 0000000000000002 si: 00007fa631ab1120 bp: 00007fa631ab1380 bx: 0000000000000006
dx: 0000000000000000 ax: 0000000000000000 cx: 00007fa641626b20 sp: 00007fa631ab1120
ip: 00007fa641626b20 efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000
trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[end of stack trace]
Calling _exit(1). Core file will not be generated.
2020-11-18T16:48:52.171Z ERROR Invoke Error {"errorType":"Error","errorMessage":"Protocol error (Page.printToPDF): Target closed.","message":"Protocol error (Page.printToPDF): Target closed.","stack":["Error: Protocol error (Page.printToPDF): Target closed."," at /opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:208:63"," at new Promise ()"," at CDPSession.send (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:207:16)"," at Page.pdf (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Page.js:1212:43)"," at Runtime.exports.handler (/var/task/index.js:28:20)"," at processTicksAndRejections (internal/process/task_queues.js:97:5)"]}
END RequestId:
REPORT RequestId: Duration: 3614.38 ms Billed Duration: 3700 ms Memory Size: 2048 MB Max Memory Used: 1240 MB Init Duration: 198.64 ms
`

@alixaxel alixaxel added duplicate This issue or pull request already exists wontfix This will not be worked on and removed bug Something isn't working labels Nov 21, 2020
@alixaxel
Copy link
Owner

@johncitak The image you're targeting is 8996x9578 pixels in size. That's 86 163 688 square pixels. 🤯

If you consider that each pixel will consume 4 bytes (one for each color + one alpha channel):

86163688 pixels * 4 bytes = 344654752 bytes = 328.69 MB

I'm ignoring any additional overhead from the PDF format.

Seems like you've allocated enough memory (2048 MB) to your Lambda, but you're also trying to store this under /tmp.

Under Lambda /tmp is limited to 512MB and just chrome-aws-lambda alone takes about 150MB of that.

This issue seems to be a duplicate of #61.

The good news is that now you can make use of EFS with Lambda to overcome this limitation. 😉

PS: Sorry for the late reply.

@citak
Copy link
Author

citak commented Dec 1, 2020

@alixaxel thank you for the response. So as I read from the other thread cache caps at 32MB and thats why it doesn't work. If I mount it with EFS and increase the cache size it should work. I tried with EFS before but I didn't point the cache to EFS. How can I set a custom path for cache? Thanks for all your help.

@vieirai
Copy link

vieirai commented Jan 25, 2021

@alixaxel thank you for the response. So as I read from the other thread cache caps at 32MB and thats why it doesn't work. If I mount it with EFS and increase the cache size it should work. I tried with EFS before but I didn't point the cache to EFS. How can I set a custom path for cache? Thanks for all your help.

Last I looked into this, you could override the default cache location in chromium with this environment variable: TMPDIR.

You can pass this into your puppeteer.launch config in the env property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants