Implement 'disposeContext' option in Configuration and EsbuildFunctionDefinitionHandler #515
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.
Description:
This pull request addresses the issue explained in #514. We identified a challenge regarding the handling of context disposal in the serverless-esbuild plugin, which caused error and changed behavior of Lambda functions on every 3rd local invoke.
Changes Made:
New 'disposeContext' Property: I introduced a new property named disposeContext which has a default value as 'true' in both Configuration and EsbuildFunctionDefinitionHandler interfaces. This property allows users to control whether the disposeContexts() function should dispose of the context.
Configuration Flexibility: The disposeContext option can be set globally within the esbuild configuration in the serverless configuration file. This global setting applies to all Lambda functions utilizing the specific configuration.
Function-Level Override: Individual functions can override the global setting by including the disposeContext property in their own configurations.
Backward Compatibility: Careful consideration has been given to ensure backward compatibility with these changes. For existing users of the serverless-esbuild library who have not specified the disposeContext option in their configurations, there will be no disruption in functionality. This is because the disposeContext property is set to a default value of 'true'. Consequently, the context disposal behavior will continue to operate as it did previously, maintaining the expected behavior for current users. This approach ensures a seamless transition for users updating to the version of the library that includes these new changes.
Testing: The testing for these changes was conducted within our own development environment, specifically tailored to our use case of programmatically invoking Lambda functions locally.
Impact of Changes:
This enhancement provides greater control over context management in Lambda functions, potentially improving performance and resource management for users of the serverless-esbuild plugin. It offers both a global and a function-specific configuration approach, catering to diverse use cases and deployment strategies.
I believe this feature can solve the problem of the ones who were facing with the same error and am looking forward to feedback from the maintainers and community.