floydspace / serverless-esbuild

💨 A Serverless framework plugin to bundle JavaScript and TypeScript with extremely fast esbuild
MIT License
445 stars 137 forks source link

Implement 'disposeContext' option in Configuration and EsbuildFunctionDefinitionHandler #515

Closed 0gebey closed 9 months ago

0gebey commented 9 months ago

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.

floydspace commented 9 months ago

hi @0gebey thank you for the detailed explanation of the issue you are facing, and the PR. could you please also update the readme with a little explanation and default value, as you are adding a new configuration option.

floydspace commented 9 months ago

@0gebey could you please also rebase your branch, I fixed the recent e2e tests issue, blocking PRs

0gebey commented 9 months ago

@0gebey could you please also rebase your branch, I fixed the recent e2e tests issue, blocking PRs

@floydspace Can you check it again ? I believe it should be okey right now.

github-actions[bot] commented 9 months ago

:tada: This PR is included in version 1.50.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: