question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lambda function does not finish and times out

See original GitHub issue

Describe the bug Hi there. I’ve been enjoying using Laconia for my lambda-based project, thanks for developing it.

I’m encountering an issue where my Lambda function executes properly, and I can see from the logs that it reaches the final line of the function (the return statement). However lambda doesn’t seem to be aware that the function has finished, so it hangs until the configured timeout and then throws a timeout error.

To Reproduce Here’s a “toy” summary of my code:

import laconia from '@laconia/core';
import myAdaptor from 'Adaptors/myAdaptor';
import getDbConfig from 'Infrastructure/database/getDbConfig';
import connect from 'Infrastructure/database/connect';

const factory1 = async () => ({ dbConfig: await getDbConfig() });
const factory2 = async ({ dbConfig }) => ({
  connection: await connect(dbConfig),
});

const app = async (event, { connection }) => {
 let result;
  try {
    result = await connection.performQuery(event);
  } catch (err) {
    console.error('query error: ', err);
    result = err;
  }
  await connection.end();
  console.log('query result: ', result);
  return { result: result };
});

export default laconia(myAdapter(app))
  .register(factory1)
  .register(factory2);

When I invoke this function, the query and logging all happens within 1 second. Then the function waits 10 seconds before returning an error:

{
  "errorMessage": "2019-06-08T17:00:51.417Z SOME_UUID Task timed out after 10.00 seconds"
}

Expected behavior

I’m expecting the function invocation to gracefully terminate at the end of the execution of the logic in the app.

Actual behavior

All logic executed, then the function waits until the timeout.

Additional context I’m using serverless-mysql as my DB client.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ceilforscommented, Jun 10, 2019

@disbelief That’s a good idea. Would you mind contributing by filing an issue describing what kind of problems you are facing when you’re creating your own adapter? It would be great if we can ensure the documentation are covering all those problems.

1reaction
ceilforscommented, Jun 9, 2019

@disbelief No worries!

That’s right, you should set it in the adapter. I can’t see your code for myAdapter, but the second argument of an adapter would be LaconiaContext, which would contain context as well, just like how you have done it in the app.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Lambda function invocation timeout errors - AWS
Retrieve the request IDs of any timed-out invocations by searching the function's Amazon CloudWatch log group for the phrase, Task timed out.
Read more >
What happens when AWS Lambda times out? - website builder
When a Lambda function times out, AWS first tries to terminate the function using the normal termination mechanisms. If this fails, AWS attempts ......
Read more >
Why is my AWS Lambda function ending before finishing with ...
Lambda will finish there itself without sending response or timeout. req.on('socket', function (socket) { socket.unref() }).
Read more >
AWS Lambda Task timed out error [Solved] | bobbyhadz
The "Task timed out after X seconds" error occurs because a lambda function's execution has exceeded its configured timeout. To view a lambda...
Read more >
Lambda Task Timed Out After X Seconds - Dashbird
The default timeout of a Lambda function is three seconds. This means, if you don't explicitly configure a timeout, your function ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found