# Task timed out randomly after successfully deploy to Netify

**URL:** <https://answers.netlify.com/t/task-timed-out-randomly-after-successfully-deploy-to-netify/40802>\
**Category:** Support\
**Tags:** netlify-newbie\
**Created:** [July 12, 2021, 11:25am UTC](https://answers.netlify.com/t/task-timed-out-randomly-after-successfully-deploy-to-netify/40802 "2021-07-12T11:25:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hoangtho1997](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hoangtho1997/32/35366_2.png) [@hoangtho1997](https://answers.netlify.com/u/hoangtho1997)\
**Post date:** [July 12, 2021, 11:25am UTC](https://answers.netlify.com/t/task-timed-out-randomly-after-successfully-deploy-to-netify/40802/1 "2021-07-12T11:25:01Z")

</div>

I’m doing some side-project with scraping dynamic contents page with `chrome-aws-lambda`.  
After i success to deploy to netlify. Somehow, i get error `ERROR Task timed out after 10.01 seconds` randomly. . I tried with local development and still working normal ( you can see the log below).

I was follow-up [this topic](https://stackoverflow.com/questions/60121944/how-to-start-launch-puppeteer-before-using-it) to make my function run-once ( to reduce the load time too) but still get the error

```plaintext
> netlify dev
◈ Netlify Dev ◈
◈ Ignored general context env var: LANG (defined in process)
◈ Ignored general context env var: LANGUAGE (defined in process)
◈ No app server detected and no "command" specified
◈ Using current working directory
◈ Unable to determine public folder to serve files from
◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.
◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection
◈ Running static server from "scrap-nodeJS"
◈ Loaded function cases.
◈ Loaded function hello.
◈ Functions server is listening on 37945

◈ Server listening to 3999

   ┌─────────────────────────────────────────────────┐
   │ │
   │ ◈ Server now ready on http://localhost:8888 │
   │ │
   └─────────────────────────────────────────────────┘

◈ Rewrote URL to /.netlify/functions/hello
Request from ::1: GET /.netlify/functions/hello
Response with status 200 in 21 ms.
◈ Rewrote URL to /.netlify/functions/cases
Request from ::1: GET /.netlify/functions/cases
Done
Response with status 200 in 2997 ms.

```

This is my current code :

```plaintext
const chromium = require('chrome-aws-lambda');
exports.handler = async function (event, context) {
    let browser;
    const launchBrowser = async () => {
        if (browser) return;
        browser = await chromium.puppeteer.launch({
            executablePath: await chromium.executablePath,
            args: chromium.args,
            defaultViewport: chromium.defaultViewport,
            headless: true,
        });
    };
    try {
        await launchBrowser()
        const page = await browser.newPage();
        await page.setRequestInterception(true);
        page.on('request', (req) => {
// prevent render css,img,only render text
            if (req.resourceType() === 'stylesheet' || req.resourceType() == 'font' || req.resourceType() == 'image') {
                req.abort();
            } else {
                req.continue();
            }
        });
        await page.goto('https://vnexpress.net/covid-19/covid-19-viet-nam');
        const element = await page.waitForSelector('.total_case_today'); // select the element
        const cases = await element.evaluate(el => el.textContent); // grab the textContent from the 
        return {
            statusCode: 200,
            body: JSON.stringify({
                cases: cases
            }),

        };
    } catch (error) {
        console.log(error);
    } finally {
        console.log("Done");
    }
};

```

---

<div class="post-metadata">

**Author:** ![coelmay](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/coelmay/32/24427_2.png) [@coelmay](https://answers.netlify.com/u/coelmay)\
**Post date:** [July 12, 2021, 11:56am UTC](https://answers.netlify.com/t/task-timed-out-randomly-after-successfully-deploy-to-netify/40802/2 "2021-07-12T11:56:50Z")

</div>

Hi @hoangtho1997

> [@hoangtho1997](#):
>
> ERROR Task timed out after 10.01 seconds

Serverless functions must complete in 10 seconds, background functions within 15 minutes as per [docs](https://docs.netlify.com/functions/overview/#default-deployment-options)

---

<div class="post-metadata">

**Author:** ![hoangtho1997](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hoangtho1997/32/35366_2.png) [@hoangtho1997](https://answers.netlify.com/u/hoangtho1997)\
**Post date:** [July 12, 2021, 12:24pm UTC](https://answers.netlify.com/t/task-timed-out-randomly-after-successfully-deploy-to-netify/40802/3 "2021-07-12T12:24:39Z")

</div>

oh no. … ☹ so sad. Any chance to increased the max time?.

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [July 12, 2021, 12:29pm UTC](https://answers.netlify.com/t/task-timed-out-randomly-after-successfully-deploy-to-netify/40802/4 "2021-07-12T12:29:22Z")

</div>

The max we can go is 26 seconds. However, we require you to be on a Pro or above team for that.

---

<div class="post-metadata">

**Author:** ![hoangtho1997](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hoangtho1997/32/35366_2.png) [@hoangtho1997](https://answers.netlify.com/u/hoangtho1997)\
**Post date:** [July 12, 2021, 12:31pm UTC](https://answers.netlify.com/t/task-timed-out-randomly-after-successfully-deploy-to-netify/40802/5 "2021-07-12T12:31:02Z")

</div>

Oh im just hobyist developer :(. Not Pro developer so it really hard to me to afford it ☹

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [July 12, 2021, 2:37pm UTC](https://answers.netlify.com/t/task-timed-out-randomly-after-successfully-deploy-to-netify/40802/6 "2021-07-12T14:37:41Z")

</div>

Unfortunately, in that case, you could write your API in a way that might finish within 10 seconds. if you’re depending on a 3-rd party API and that’s taking long, maybe you can switch to another API that might be faster. If that’s not possible, you’d have to host your API elsewhere.
