Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: memory leak in event triggers #1075

Merged
merged 1 commit into from
Nov 3, 2024

Conversation

niekschoemaker
Copy link
Contributor

Please describe the changes this PR makes:
The trigger creates a "trigger" function which saves the context into the _listeners map in the client.

Each time this function get's triggered the response is pushed into the responses array, which is created once, on startup. This causes a memory leak which saves all responses during the lifetime of the bot.

By moving the respones array into the function itself this is resolved and it will only return the responses for that specific trigger and the array can be garbage collected after this.

For a quick example of this bug on production (running for around a week with 100k members):
{74CE638F-7DDE-4B3D-BC85-BE8B558F2492}

This array uses about 250 MB of memory, which is about 90% of all memory usage, and the array only contains empty objects returned from the execute function.

@vijayymmeena
Copy link
Member

@niekschoemaker thanks, could you please bump the patch as well for auto release.

Just run npx changeset and npx chageset version

@niekschoemaker
Copy link
Contributor Author

@niekschoemaker thanks, could you please bump the patch as well for auto release.

Just run npx changeset and npx chageset version

Done, did it with a force push to avoid a unecessary commit.

@vijayymmeena vijayymmeena merged commit 4bf6131 into discordx-ts:main Nov 3, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants