feat(watch): propagate SIGINT and SIGTERM signals to function if extensions are registered #853
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: