Skip to content

Support IDisposable for Function Handlers #342

Closed

Description

@nerdamigo

Issue #131 already touched on this - but I'd like to suggest that while it discusses wanting to do cleanup after each invocation, there is also a use case for wanting to do cleanup on closure of the execution environment.

For cleanup within the context of an execution, the suggested approach from normj works well (just wrap the actual function handler's method body w/ a using statement, and have a custom class implement IDisposable.

However, if (for example) I wanted to Bootstrap a DI container in the constructor, and dispose of it when the execution environment "shuts down" the lack of support for IDisposable on the wrapping class becomes more apparent.

I considered using a destructor, but believe the shared contract of IDisposable is a better solution overall.

Activity

  1. normj commented on Nov 12, 2018

    @normj
    Member

    If you are wanting for code to be called when the Lambda service reclaims the execution environment there is no service hook for that to happen. When the Lambda service detects a frozen execution environment that hasn't been used in awhile it deletes the execution environment regardless of what is inside the execution environment.

  2. nerdamigo commented on Nov 12, 2018

    @nerdamigo
    Author

    Well that's too bad - was there a design decision for the Lamda environment that precludes it from offering such a service hook?

  3. added
    guidanceQuestion that needs advice or information.
    and removed on Jan 3, 2019
  4. normj commented on Feb 9, 2019

    @normj
    Member

    Closing as there isn't anything more we can do from the .NET side. There would need to be a service behavior change for us to do anything more. For general Lambda comments I would suggest adding post to the Lambda forum where members of the Lambda team will see it. https://forums.aws.amazon.com/forum.jspa?forumID=186

  5. Dreamescaper commented on Oct 16, 2025

    @Dreamescaper
    Contributor

    @normj

    Hi!

    when the Lambda service reclaims the execution environment there is no service hook for that to happen

    Is this still true?
    Per my understanding, Lambda now sends SIGTERM signal to runtime before killing it. Would it be possible to use it for disposal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    guidanceQuestion that needs advice or information.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions