aws-samples / aws-lambda-extensions

A collection of sample extensions to help you get started with AWS Lambda Extensions
MIT No Attribution
442 stars 145 forks source link

SIGTERM in custom-runtime-extension-demo #63

Closed ianic closed 11 months ago

ianic commented 2 years ago

I'm analyzing (and playing with) code in the custom-runtime-extension-demo and can't understand when the runtime gets SIGTERM. So far I understand that in line 41 code starts waiting for curl to finish. That is start of new invocation. There we also trap SIGTERM. But I can't got that _term function to be executed ever. It seams that the runtimes gets KILL instead of TERM signal. So this example may be a bit misleading.

@julianwood can you please help me understand that runtime behavior a little bit more. Thanks.

ianic commented 2 years ago

The above observation holds true when there are no extensions registered. When I add extension layer then the runtime receives SIGTERM. So there are two different behavior of the runtime (bootstrap) in the provided.al2 Lambda.

When there are no extensions then the bootstrap, which is frozen waiting for /next invocation, gets killed when the Lambda process environment is shutting down. Without getting SIGTERM. If we register extension then we also have a chance to catch SIGTERM in the bootstrap.

Am I observing this correctly.

julianwood commented 2 years ago

Hi, When there is at least one extension registered (internal or external) the runtime gets SIGTERM on shut down, otherwise it gets SIGKILL. This is the behaviour that is expected currently.