# Netlify functions stops running after return?

**URL:** <https://answers.netlify.com/t/netlify-functions-stops-running-after-return/74510>\
**Category:** Support\
**Tags:** lambda-functions\
**Created:** [August 30, 2022, 11:52am UTC](https://answers.netlify.com/t/netlify-functions-stops-running-after-return/74510 "2022-08-30T11:52:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarcFuSa](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/marcfusa/32/23695_2.png) [@MarcFuSa](https://answers.netlify.com/u/MarcFuSa)\
**Post date:** [August 30, 2022, 11:52am UTC](https://answers.netlify.com/t/netlify-functions-stops-running-after-return/74510/1 "2022-08-30T11:52:40Z")

</div>

Hi Guys N Girls

I have a question regarding netlify’s background functions.

Imagine this situation:

```auto
try {
    await someAwaitedFunction()
} 
try {
    await someOtherAwaitedFunction()
} 
try {
    someSynchronousFunction()
} 
finally {
    return {
        statusCode: 200
    }
}

```

Is my assumption correct, that. `someSynchronousFunction()` might not getting fully executed, because the function has completed by the return statement in the finally-block?

Thing is, `someSynchronousFunction()` does something that takes time and I don’t want the user to wait for it. In my case its sending Emails with nodeMailer. Sometimes it takes a lot of time, and then I will get this error (locally):

`{"errorMessage":"Task timed out after 10.00 seconds","errorType":"TimeoutError","level":"error","stackTrace":["new TimeoutError (/usr/local/lib/node_modules/netlify-cli/node_modules/lambda-local/build/lib/utils.js:112:28)","Context.<anonymous> (/usr/local/lib/node_modules/netlify-cli/node_modules/lambda-local/build/lib/context.js:110:19)","listOnTimeout (node:internal/timers:559:17)","processTimers (node:internal/timers:502:7)"]}`

Sometimes it takes so long that this above error appears, sometimes it works within the time.  
Locally I will receive the emails, when testing live, the emails doesn’t get sent.

---

<div class="post-metadata">

**Author:** ![clarnx](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/clarnx/32/40777_2.png) [@clarnx](https://answers.netlify.com/u/clarnx)\
**Post date:** [August 31, 2022, 8:14am UTC](https://answers.netlify.com/t/netlify-functions-stops-running-after-return/74510/3 "2022-08-31T08:14:16Z")

</div>

hello @MarcFuSa,  
By default, all functions are deployed with:

- us-east-1 AWS Lambda region
- 1024MB of memory
- 10 second execution limit for synchronous functions

> [@MarcFuSa](#):
>
> “errorMessage”:"Task timed out after 10.00

In your case since the EXECUTION LIMIT for Netlify functions is 10 seconds, the execution of the `someSynchronousFunction()` will NOT complete if it takes more than 10 seconds. Hence the error you are getting.

If you want to run functions for longer periods, Netlify has a new Beta feature called Background Functions.  
Netlify’s Background Functions provide an option for serverless functions that run for up to 15 minutes.  
You can read more about Background Functions at [https://docs.netlify.com/functions/background-functions/](https://docs.netlify.com/functions/background-functions/)

Hope this helps.

---

<div class="post-metadata">

**Author:** ![MarcFuSa](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/marcfusa/32/23695_2.png) [@MarcFuSa](https://answers.netlify.com/u/MarcFuSa)\
**Post date:** [August 31, 2022, 9:35am UTC](https://answers.netlify.com/t/netlify-functions-stops-running-after-return/74510/4 "2022-08-31T09:35:13Z")

</div>

Hi Clarnx

Oh didn’t realize that there are background-functions are different from functions.

From the docs:

> Background function syntax is similar to synchronous function syntax, but you will generally pass the function result to a destination other than the originating client.

_… “to a destination other than the originating client”_

So, how would I send the response to the clientside-function that called this background-function?

The nodemailer-example in the docs doesn’t return anything, just console log the outcome.

---

<div class="post-metadata">

**Author:** ![clarnx](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/clarnx/32/40777_2.png) [@clarnx](https://answers.netlify.com/u/clarnx)\
**Post date:** [August 31, 2022, 12:26pm UTC](https://answers.netlify.com/t/netlify-functions-stops-running-after-return/74510/5 "2022-08-31T12:26:30Z")

</div>

@MarcFuSa it is true you will generally pass the function result to a destination other than the originating client.  
So for example for background functions you can probably send the result to an email, or forward the raw response to a webhook.

However in your case a background function can still send the emails but you cannot send a response to the function that called the Background function.

Note that the use cases of a regular Netlify function is to perform tasks that do not run for long periods. If your function takes more than 10 seconds then the only option you have is Background function. The downside is that you cannot send a response from the Background function.
