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

fix: remove 1 sec delay on invoke #6418

Merged
merged 9 commits into from
Dec 8, 2023
Merged

Conversation

sidhujus
Copy link
Contributor

@sidhujus sidhujus commented Dec 7, 2023

Which issue(s) does this change fix?

#6173

Why is this change necessary?

Currently there is an explicit 1 second sleep in the code to work around a race condition and ensure that everything that is printed to the cli is done in the correct order.

The original race condition occurs when the main thread finishes its execution and prints the flask response to stdout, while there are still some things from the docker container that need to be printed.

This can be reproduced currently by the following steps (after removing the sleep in dev version of sam)

1. sam init a hello world template (I did any version of node.js)
2. change the lambda code to just print something
3. samdev local start-lambda -t template.yaml
4. aws lambda invoke --endpoint http://localhost:3001 --function-name HelloWorldFunction out.txt (in a separate console)
5. repeat step 4 until the ordering of the output is incorrect (The final thing printed is not the following)
6. 2023-12-07 14:41:35 127.0.0.1 - - [07/Dec/2023 14:41:35] "POST /2015-03-31/functions/HelloWorldFunction/invocations HTTP/1.1" 200

How does it address the issue?

using a threading.Event, that gets set only when the regex matches the pattern, to wait until it is safe to end the flask request

What side effects does this change have?

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sidhujus sidhujus requested a review from a team as a code owner December 7, 2023 22:51
@github-actions github-actions bot added area/local/start-api sam local start-api command area/local/invoke sam local invoke command area/local/start-invoke labels Dec 7, 2023
@sidhujus sidhujus requested a review from hawflau December 8, 2023 18:39
@sidhujus sidhujus added this pull request to the merge queue Dec 8, 2023
Merged via the queue into aws:develop with commit c39659c Dec 8, 2023
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/local/invoke sam local invoke command area/local/start-api sam local start-api command area/local/start-invoke
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants