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

lambda-local does not wait for empty event loop #128

Closed
pbostrom opened this issue Dec 22, 2017 · 4 comments · Fixed by #164
Closed

lambda-local does not wait for empty event loop #128

pbostrom opened this issue Dec 22, 2017 · 4 comments · Fixed by #164
Labels

Comments

@pbostrom
Copy link

pbostrom commented Dec 22, 2017

lambda-local does not appear to wait for empty event loop. The below function should log "done" after a 1000ms timeout, but it returns before logging. I've tested with and without the -n flag.

exports.handler = function(event, context, callback) {
  setTimeout(function() {
    console.log("done");
  }, 1000);
  context.succeed("Success");
}
$ lambda-local -l wait.js -e examples/event.js
info: START RequestId: 35f859c1-2627-3dd6-0dd0-11792f24eef9
info: End - Message
info: ------
info: Success
info: ------
info: Lambda successfully executed in 9ms.
$ lambda-local -n -l wait.js -e examples/event.js
info: START RequestId: 751dc0a1-f981-9537-6e8e-880a910be8fa
info: End - Message
info: ------
info: Success
info: ------
info: Lambda successfully executed in 8ms.
@gpotter2 gpotter2 added the bug label Dec 23, 2017
@gpotter2
Copy link
Collaborator

Hi, thanks for reporting
This seems to be a bug, however, i'm not sure that it's fixable in lambda-local.

I will try to investigate, but I don't see a way to wait for all unregistered setTimeout from outside its caller...

@gpotter2
Copy link
Collaborator

gpotter2 commented Jun 6, 2018

FTR: I'm waiting for nodejs/node#21102 to be published before using it to fix this issue

@gpotter2
Copy link
Collaborator

@pbostrom Hello ! I don't know if you remember this issue, or if you still use lambda-local, but I finally fixed this.
Could you retry against master ? Your example is now passing

@pbostrom
Copy link
Author

lgtm

$ ./bin/lambda-local -l wait.js -e examples/event_s3-put.js --wait-empty-event-loop
info: START RequestId: 4958dd18-ef2b-df40-0e68-8043bba2bbbe
info: End - Message
info: ------
info: Success
info: ------
done
info: Lambda successfully executed in 1054ms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants