feat(watch): propagate SIGINT and SIGTERM signals to function if extensions are registered#853
Merged
calavera merged 1 commit intocargo-lambda:mainfrom May 6, 2025
Merged
Conversation
8bbaa45 to
7945904
Compare
…nsions are registered
calavera
approved these changes
May 6, 2025
Collaborator
calavera
left a comment
There was a problem hiding this comment.
This is really cool, thanks for implementing it!
Contributor
Author
|
@calavera don't suppose you'd be up for a new release once this lands? I have some PRs out to the rust lambdas runtime with some examples that depend on these changes. Would be great to have them work locally out of the box! |
This was referenced May 6, 2025
Collaborator
|
I can do a release with these changes on Wednesday. Let me check first if there is anything else I could add to it. |
Contributor
Author
|
Awesome! Much appreciated. |
calavera
approved these changes
May 6, 2025
Contributor
|
This pull request has been automatically locked. Create a new discussion if you'd like to continue the conversation. https://github.com/cargo-lambda/cargo-lambda/discussions/new?category=general |
Collaborator
|
Version 1.8.5 released with this patch. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: #850
Adding some rudimentary signal propagation to allow testing graceful shutdown logic via
cargo lambda watch.As a refresher,
SIGTERMandSIGINTare sent to functions if and only if at least one extension is registered. And then, the delay beforeSIGKILLis 500ms if there is an internal extension registered, or 300ms if only an external.More information can be found here:
https://github.com/aws-samples/graceful-shutdown-with-aws-lambda
My use case is that I want to validate function graceful shutdown logic without relying on opaque AWS decisions on when to kill a running function.
I added some minimalist logic to somewhat mirror the above:
cargo lambda watchprocess, check whether either extension type was set, and return the corresponding shutdown delay if soSIGKILLif not done in time. Either way, clean up thewatchexec.I did NOT implement the following:
watchexecaction outcomes with non-watch-exec logic inbetween, I didn't bother futzing with itSHUTDOWNevents / signals - this would have been much larger scopeThese gaps are documented in the new doc section for this PR. If somebody needs any of those features, presumably they could layer them on top down the road.
Testing
My graceful shutdown testbed was this file.
With my new logic,
Control-C-ing on my watch task in debug mode generated:If I add a second-long sleep (longer than the 500ms delay before SIGKILL), I instead see the shutdown not complete:
Some sort of warn message that time ran out would be nice, but as I mentioned, it's pretty klunky trying to chain non-watchexec logic inside the outcomes, so I didn't bother.
Finally, in a function with NO extensions registered, I don't see graceful shutdown attempted at all: