Lambda handler runaway promise
Closed this issue · 2 comments
Aconradty commented
Description:
Promise returned by handler.runHandler()
is ignored but should be awaited. (serverless-s3-local/index.js
Line 440)
Steps to reproduce:
- Edit the file
example/put_with_s3_event_response/handler.js
to look like the code provided below. - Run the command
yarn workspace put-with-s3-event-response run start
to start the app. - Trigger the endpoint multiple times by running the script provided below.
- Wait until the app throws an error like the one provided below.
Code for example/put_with_s3_event_response/handler.js
:
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3"
export const webhook = (event, context, callback) => {
const client = new S3Client({
forcePathStyle: true,
credentials: {
accessKeyId: "S3RVER",
secretAccessKey: "S3RVER",
},
endpoint: "http://localhost:8000",
});
client
.send(
new PutObjectCommand({
Bucket: "existing-bucket",
Key: `${Math.random()}/${Math.random()}/data.txt}`.toString(),
Body: Buffer.from(`${Math.random()}`),
})
)
.then(() => {
callback(null, "ok");
});
};
export const s3EventResponse = (event, context, callback) => {
console.log("S3 Event HEARD");
callback(null, "ok");
};
Script for triggering the endpoint:
#!/bin/bash
for i in {1..1000}
do
curl http://0.0.0.0:3000/dev
done
Expected error message:
GET /dev (λ: webhook)
✖ Uncaught exception
Environment: linux, node 18.11.0, framework 3.30.1 (local), plugin 6.2.3, SDK 4.3.2
Docs: docs.serverless.com
Support: forum.serverless.com
Bugs: github.com/serverless/serverless/issues
Error:
Error: [504] - Lambda timeout.
at #timeoutAndTerminate (file:///home/xxx/git/serverless-s3-local/node_modules/serverless-offline/src/lambda/LambdaFunction.js:283:11)
at async LambdaFunction.runHandler (file:///home/xxx/git/serverless-s3-local/node_modules/serverless-offline/src/lambda/LambdaFunction.js:305:16)
1 deprecation found: run 'serverless doctor' for more details
/home/xxx/git/serverless-s3-local/node_modules/essentials/index.js:21
throw reason;
^
LambdaTimeoutError: [504] - Lambda timeout.
at #timeoutAndTerminate (file:///home/xxx/git/serverless-s3-local/node_modules/serverless-offline/src/lambda/LambdaFunction.js:283:11)
at async LambdaFunction.runHandler (file:///home/xxx/git/serverless-s3-local/node_modules/serverless-offline/src/lambda/LambdaFunction.js:305:16)
Node.js v18.11.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 1
Proposed Solution:
- add async keyword to the
func
function in line 424 - add await keyword to the
lambda.runHandler
function in line 440
ar90n commented
Hi @Aconradty
Thanks for your great work!!
I merged your PR about this issue and released v0.7.2.
Please try it !!
Aconradty commented
Thank you very much for that blazing fast release. The test mentioned above now works without any error.