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] No longer working in Lambda #271

Open
fire015 opened this issue Apr 30, 2024 · 46 comments
Open

[BUG] No longer working in Lambda #271

fire015 opened this issue Apr 30, 2024 · 46 comments
Labels
bug Something isn't working

Comments

@fire015
Copy link

fire015 commented Apr 30, 2024

package.json:

    "@sparticuz/chromium": "123.0.1",
    "puppeteer-core": "22.6.4"

code:

  chromium.setGraphicsMode = false;

  console.log("## Launching browser");
  const browser = await puppeteer.launch({
    args: chromium.args,
    defaultViewport: chromium.defaultViewport,
    executablePath: await chromium.executablePath(),
    headless: chromium.headless,
    ignoreHTTPSErrors: true,
  });

  console.log("## Creating new page");
  const page = await browser.newPage();

  console.log("## Setting user agent");
  await page.setUserAgent("Lambda PDF");

  console.log("## Going to " + url);
  await page.goto(url, {
    waitUntil: ["domcontentloaded", "networkidle0"],
  });

It's freezing after "Creating new page" appears in the console logs.

Lambda 18.x (tried with 20.x too) with 2GB memory
Runtime version ARN: arn:aws:lambda:eu-west-2::runtime:b475b23763329123d9e6f79f51886d0e1054f727f5b90ec945fcb2a3ec09afdd

@fire015 fire015 added the bug Something isn't working label Apr 30, 2024
@fire015
Copy link
Author

fire015 commented Apr 30, 2024

Downgrading to:

    "@sparticuz/chromium": "122.0.0",
    "puppeteer-core": "22.5.0"

Seems to have worked. Leaving this open just to verify I didnt make a mistake selecting the wrong package versions?

@leepa
Copy link

leepa commented Apr 30, 2024

This issue hit us today but we've not updated for a while so it seems to effect old versions too. Is there anyway to make this project dump a stacktrace when the browser crashes?

@Sparticuz
Copy link
Owner

Make sure to leave graphics mode enabled. The option will be fixed in the next version. I've been traveling so I haven't had time to update to chromium 124.

@Sparticuz
Copy link
Owner

Sparticuz commented Apr 30, 2024

This issue hit us today but we've not updated for a while so it seems to effect old versions too. Is there anyway to make this project dump a stacktrace when the browser crashes?

You can add puppeteer.launch({dumpio:true}) in the object.

@shubhamvyapar
Copy link

shubhamvyapar commented Apr 30, 2024

We have also started facing same issue. We have not update package version from 3 months. While trying to figure out the issue, we found that it is not working only when html contains https URLs as we had some https URLs in img tag and link tag. With http urls, it is working fine.

We had the following package.json

 "@sparticuz/chromium": "^109.0.5",
 "puppeteer-core": "^19.4.0",

Same thing is working fine with https URLs after updating package version to (as mentioned by @fire015 )

"@sparticuz/chromium": "122.0.0",
"puppeteer-core": "22.5.0"

@ryan-concora
Copy link

Having the same issue, not working in our production app.

@urvik-bhalala
Copy link

Downgrading to:

    "@sparticuz/chromium": "122.0.0",
    "puppeteer-core": "22.5.0"

Seems to have worked. Leaving this open just to verify I didnt make a mistake selecting the wrong package versions?

Solved.

In my case, Downgrading to version as you describe and additionally I have to install "web-streams-polyfill" package. And added this line : global.ReadableStream = require('web-streams-polyfill').ReadableStream;

@leepa
Copy link

leepa commented Apr 30, 2024

We've worked around it by rolling back to the previous Lambda Runtime ARN.

@ryan-concora
Copy link

We've worked around it by rolling back to the previous Lambda Runtime ARN.

How do you do this with Serverless framework?

@iLykaPaul
Copy link

iLykaPaul commented Apr 30, 2024

We also ran into this today, the version changes suggested above:

"@sparticuz/chromium": "122.0.0",
"puppeteer-core": "22.5.0"

and in our case an upgrade of the Chromium Lambda Layer to latest was the change combination that got us back up and running.

@ryan-concora
Copy link

Ours doesn't seem to want to pull from s3

"An executablePathorchannelmust be specified forpuppeteer-core" name:"Error" stacktrace:"at assert (/var/task/node_modules/puppeteer-core/lib/cjs/puppeteer/util/assert.js:18:15) at ChromeLauncher.computeLaunchArguments (/var/task/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:102:36) at async ChromeLauncher.launch (/var/task/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:70:28) at async CoverPageGenerator.generatePDF (/var/task/src/CoverPage.js:60:19) at async _getCoverPage (/var/task/src/zip.js:72:10) at async exports.createSubmittal (/var/task/src/zip.js:33:21) at async Worker.work (/var/task/src/worker.js:25:27) at async post (/var/task/src/handler.js:19:3)" type:"ERROR_TYPE_UNCAUGHT"

@xanharris
Copy link

xanharris commented May 1, 2024

We've worked around it by rolling back to the previous Lambda Runtime ARN.

How do you do this with Serverless framework?

@ryan-concora
Specify the run time management at the "provider" or "function" level in your serverless.yml file:

functions:
  hello:
    runtimeManagement:
      mode: manual
      arn: arn:aws:lambda:us-east-1::runtime:0cdcfbdefbc5e7d3343f73c2e2dd3cba17d61dea0686b404502a0c9ce83931b9

The ARN version in the example above works for me (The offending ARN is mentioned in OP: #271 (comment))
Reference: https://www.serverless.com/framework/docs-providers-aws-guide-functions

@gaurav112
Copy link

Facing the same issue.

Error: spawn Unknown system error -8

"@sparticuz/chromium": "^110.0.0",
"puppeteer": "19.6.0"
const browser = await puppeteer.launch({
    dumpio: true,
    args: chromium.args,
    executablePath: await chromium.executablePath(),
    headless: true,
    ignoreHTTPSErrors: true,
})

Tried upgrading to

Downgrading to:

    "@sparticuz/chromium": "122.0.0",
    "puppeteer-core": "22.5.0"

Seems to have worked. Leaving this open just to verify I didnt make a mistake selecting the wrong package versions?

This still did not work. Any other ideas ??

@ryan-concora
Copy link

Facing the same issue.

Error: spawn Unknown system error -8

"@sparticuz/chromium": "^110.0.0",
"puppeteer": "19.6.0"
const browser = await puppeteer.launch({
    dumpio: true,
    args: chromium.args,
    executablePath: await chromium.executablePath(),
    headless: true,
    ignoreHTTPSErrors: true,
})

Tried upgrading to

Downgrading to:

    "@sparticuz/chromium": "122.0.0",
    "puppeteer-core": "22.5.0"

Seems to have worked. Leaving this open just to verify I didnt make a mistake selecting the wrong package versions?

This still did not work. Any other ideas ??

Our solution:

  • Added lambda layer, pulling from s3 doesn't seem to be working
  • Used this as executable path (examples need updating chromium.executablePath('/opt/nodejs/node_modules/@sparticuz/chromium/bin';
  • Removed "@sparticuz/chromium-min": "122.0.0"
  • Added as dev dep "@sparticuz/chromium": "122.0.0"
  • "puppeteer-core": "22.5.0"
  • Used v122.0.0 lambda layer

@LinusU
Copy link

LinusU commented May 1, 2024

Removing our disabling of the graphics mode solved this for us:

- chromium.setGraphicsMode = false
+ // FIXME: re-enable in Chromium 124
+ // ref: https://github.com/Sparticuz/chromium/issues/271#issuecomment-2085784736
+ // chromium.setGraphicsMode = false

with the following versions:

    "@sparticuz/chromium": "123.0.1",
    "playwright-core": "1.43.1",

edit: actually, not sure about this, we're still seeing some errors

@2803media
Copy link

We've worked around it by rolling back to the previous Lambda Runtime ARN.

How do you do this with Serverless framework?

change this in the Runtime management configuration:

Screenshot 2024-05-01 at 16 07 42

@JakeDluhy
Copy link

FWIW I was able to get it working with:

"@sparticuz/chromium": "122.0.0",
"puppeteer-core": "^21.1.1",
"puppeteer-extra": "^3.3.6",
"puppeteer-extra-plugin-stealth": "^2.11.2",

@adefemi
Copy link

adefemi commented May 1, 2024

setting this works
chromium.setGraphicsMode = true;

@AkbarHabeeb
Copy link

  1. @Sparticuz Little curious to understand why the below version of packages are getting into an error when the latest package version was released? What is the breaking change we have?
    "@sparticuz/chromium": "^106.0.2" "puppeteer-core": "^18.0.5"
  2. @shubhamvyapar For the suggested downgrade version "@sparticuz/chromium": "122.0.0", "puppeteer-core": "22.5.0", looks like we need Node 18, Can you kindly suggest any compatible version for Node 16 runtime env?

We got into an error saying Navigation failed because browser has disconnected! seems like chrome crashed. Is this the same issue?

@jmartinezgdev
Copy link

setting this works chromium.setGraphicsMode = true;

This worked also for me
chromium.setGraphicsMode = true;

puppeteer-core 22.6.0
@sparticuz/chromium 123.0.1,

@casyalex
Copy link

casyalex commented May 2, 2024

I am curious about the root cause, seems it relate to SSL lib update, but why GraphicsMode can make it solved.

@vishwassingh47
Copy link

We got into an error saying Navigation failed because browser has disconnected! seems like chrome crashed. Is this the same issue?

Yes we were getting the same error "Navigation failed because browser has disconnected!", but it was happening in those cases only where were are loading some asset using https, http and setOfflineMode(true) works fine.

@gaurav112
Copy link

This works for us.

We migrated to a previous version of Runtime on lambda(Node.Js 18.*)

ARN: arn:aws:lambda:ap-south-1::runtime:0cdcfbdefbc5e7d3343f73c2e2dd3cba17d61dea0686b404502a0c9ce83931b9

package.json for compatibility.

"@sparticuz/chromium": "^119.0.0",
"puppeteer": "^21.5.2"

@bjoepfeiffer
Copy link

I am having a similar issue to some of the more recently posted comments in this thread:

Navigation failed because browser has disconnected...

Others are saying that downgrading versions helped them, but I am starting to wonder if there is something else at play here. This has crept up for many of us on all different versions.

Is there a corrupted browser object being cached between lambda executions and deploys?

Is it the downgraded version or the deploy of the downgraded version that is actually fixing the issue? I am wondering if this issue creeps back up for those who have said it has been fixed with a version downgrade.

We started seeing this with these versions, which were previously working for a year. Then all of a sudden we started getting the error.

"@sparticuz/chromium": "114.0.0",
"puppeteer-core": "20.7.3"

Did AWS change something with lambdas and lambda layers that is biting all of us?

@Sparticuz
Copy link
Owner

Did AWS change something with lambdas and lambda layers that is biting all of us?

Yes, AWS updated some libraries that are causing issues with the libraries included in this package. I'm in contact with the team at AWS and we will be working on a solution.

I would recommend pinning the lambda execution environment while this issue gets sorted.

@tomasalvarez13
Copy link

I'm having a similar issue; it suddenly stopped working and started giving us this error code:

The input directory "/opt/nodejs/node_modules/@sparticuz/chromium/bin/" does not exist.
I've tried all the solutions mentioned above, but none of them worked.

@Sparticuz Sparticuz pinned this issue May 2, 2024
@tomasalvarez13
Copy link

I rolled back manualy the runtime version and it worked

@raducretu
Copy link

on one of my projects it works, on a different one, same settings same packages it does not work

@tyanko1
Copy link

tyanko1 commented May 2, 2024

@tomasalvarez13 which runtime version worked for you, specifically?

@raducretu
Copy link

@tomasalvarez13 which runtime version worked for you, specifically?

for me the one that worked on one place and didn't work on a different project is:
node 18.x
"puppeteer-core": "^22.6.2",
chromium-v123.0.1-layer.zip

same configuration on one account works on the other one it does not work, it goes timeout on:
const page = await browser.newPage();

@tomasalvarez13
Copy link

@tyanko1 one from 27/04/2024

@LinusU
Copy link

LinusU commented May 3, 2024

@raducretu you can specify the exact version of the runtime under something called "runtime management configuration". If you look at your logs from when things worked (a few days ago) you should see which arn they are using as it's printed in the INIT_START. Look for your old arn that worked, and then go in and change it to that for your Lambda.

More info here: https://docs.aws.amazon.com/lambda/latest/dg/runtimes-update.html

@fernedingd
Copy link

For everyone that is still experiencing issues after pinning the runtime version: check if you're properly closing the browser at the end of your lambda.

Our function was running fine for over a year with puppeteer-core 19.7.4 and chromium 111.0.0. After pinning the runtime version, it was kind of working again, but crashed regularly under load. Turns out we never closed the browser, which hasn't been an issue before. Changing

try {
    const browser = await puppeteer.launch({
        // ...
    });
    const page = await browser.newPage();
    // ... actions
    await page.close();
} catch {
    // ... error handling
}

to

var browser;
try {
    browser = await puppeteer.launch({
        // ...
    });
    const page = await browser.newPage();
    // ... actions
    for (const page of await browser.pages()) {
        await page.close();
    }
} catch {
    // ... error handling
} finally {
    if (browser) {
        await Promise.race([browser.close(), browser.close(), browser.close()]);
    }
}

along with pinning the version fixed the issues for us, it's been running fine for a few hours now.

@bjoepfeiffer
Copy link

We were running our pdf export lambdas on nodejs18.x. Upgrading to nodejs20.x fixed this issue for now.

@LinusU
Copy link

LinusU commented May 3, 2024

@fernedingd what is the reasoning behind using await Promise.race([browser.close(), browser.close(), browser.close()]) instead of just await browser.close()? 🤔

@fernedingd
Copy link

fernedingd commented May 3, 2024

@LinusU we initially removed the await browser.close() call because it wasn't working reliably and the funktion worked without it. Calling close multiple times was a suggestion from the FAQs. A single call should be enough, but I didn't want to risk having those issues again during peak production workloads over the weekend

@RubensMalaguteO7S
Copy link

We were running our lambda on nodejs16.x and it couldn't be changed for internal reasons. The solution found was to revert the lambda runtime to a version from before the problem and update chromium and puppeteer-core versions to:

"@sparticuz/chromium": "122.0.0"
"puppeteer-core": "17.1.3"

@solancer
Copy link

solancer commented May 7, 2024

This works for us.

We migrated to a previous version of Runtime on lambda(Node.Js 18.*)

ARN: arn:aws:lambda:ap-south-1::runtime:0cdcfbdefbc5e7d3343f73c2e2dd3cba17d61dea0686b404502a0c9ce83931b9

package.json for compatibility.

"@sparticuz/chromium": "^119.0.0",
"puppeteer": "^21.5.2"

This worked, thankyou

@hasan-wajahat
Copy link

👀

@alejandro-gstack
Copy link

@raducretu you can specify the exact version of the runtime under something called "runtime management configuration". If you look at your logs from when things worked (a few days ago) you should see which arn they are using as it's printed in the INIT_START. Look for your old arn that worked, and then go in and change it to that for your Lambda.

More info here: https://docs.aws.amazon.com/lambda/latest/dg/runtimes-update.html

This worked for us! Lambdas are up and running after a couple of days of 🔥... But waiting for a definitive solution.

@davidhongpulsifi
Copy link

davidhongpulsifi commented May 9, 2024

INIT_START Runtime Version: nodejs:18.v24	Runtime Version ARN: arn:aws:lambda:eu-central-1::runtime:c09960ad0af4321e1a7cf013174f7c0d7169bf09af823ca2ad2f93c72ade708a

INIT_START Runtime Version: nodejs:18.v24	Runtime Version ARN: arn:aws:lambda:ap-southeast-1::runtime:c09960ad0af4321e1a7cf013174f7c0d7169bf09af823ca2ad2f93c72ade708a

Working with runtime above by configure lambda runtime manually

@vince0946
Copy link

vince0946 commented May 10, 2024

We've worked around it by rolling back to the previous Lambda Runtime ARN.

How do you do this with Serverless framework?

serverless: maybe need version 3.x+ since it is a new feature last year, https://www.serverless.com/framework/docs-providers-aws-guide-functions
aws cli: https://docs.aws.amazon.com/cli/latest/reference/lambda/put-runtime-management-config.html
You should use lambda runtime management config, and find the old lambda arn in previous log which you could success running. "Runtime Version ARN: xxxx"

@davidhongpulsifi
Copy link

davidhongpulsifi commented May 10, 2024

We've worked around it by rolling back to the previous Lambda Runtime ARN.

How do you do this with Serverless framework?

serverless: maybe need version 3.x+ since it is a new feature last year, https://www.serverless.com/framework/docs-providers-aws-guide-functions aws cli: https://docs.aws.amazon.com/cli/latest/reference/lambda/put-runtime-management-config.html You should use lambda runtime management config, and find the old lambda arn in previous log which you could success running. "Runtime Version ARN: xxxx"


import { custom } from './custom';
import { functions } from './functions';
import { plugins } from './plugins';
import { stepFunctions } from './step-functions';

export const main = {
    service: some-report-fn',
    frameworkVersion: '3',
    useDotenv: true,
    configValidationMode: 'error',
    package: {
        individually: true,
    },
    provider: {
        name: 'aws',
        runtime: 'nodejs18.x',
        runtimeManagement: {
            mode: 'manual',
            arn: 'arn:aws:lambda:${opt:region}::runtime:${ssm:/configs/LAMBDA_NODEJS18_RUNTIME_ARN}',
        },

how we do now is store the ARN into SSM then map to runtimemanagement > arn

@activeliang
Copy link

setting this works chromium.setGraphicsMode = true;

This worked also for me chromium.setGraphicsMode = true;

puppeteer-core 22.6.0 @sparticuz/chromium 123.0.1,

setting this works chromium.setGraphicsMode = true;

This worked also for me chromium.setGraphicsMode = true;

puppeteer-core 22.6.0 @sparticuz/chromium 123.0.1,

This worked also for me

@denlukia
Copy link

To everyone who's reading this thread looking for answers for Vercel, what eventually worked for me:

(I'm not sure what here is responsible for a fix)

  1. Set engine in project settings to 20.x
  2. Switched from pnpm to npm
  3. Updated @sparticuz/chromium-min to newest (123.0.1 as of writing)
  4. Updated chromium tar link also to newest (chromium-v123.0.1-pack.tar as of writing)

Just in case: puppeteer-core is "^21.3.8"

@krewetka
Copy link

Yes, AWS updated some libraries that are causing issues with the libraries included in this package. I'm in contact with the team at AWS and we will be working on a solution.

I would recommend pinning the lambda execution environment while this issue gets sorted.

@Sparticuz any news on this? Pinning to older version for a long run is not perfect solution for security reasons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests