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

[BUG] Memory leaks when compiling schema #46

Closed
LonelyPrincess opened this issue Feb 2, 2022 · 0 comments · Fixed by #47
Closed

[BUG] Memory leaks when compiling schema #46

LonelyPrincess opened this issue Feb 2, 2022 · 0 comments · Fixed by #47
Assignees
Labels
bug Something isn't working

Comments

@LonelyPrincess
Copy link
Contributor

LonelyPrincess commented Feb 2, 2022

There has been reports of the ajv.compile method causing memory leaks, an issue that will directly affect any user making use of the validation methods provided by this library, as well as anyone using express-oas-validator. More information can be found in the links below:

For what it's mentioned in the comments of these threads, those memory leaks could origin in a wrong usage of the library, not so much a bug on it. Thus, updating our dependency to the latest version of the ajv library doesn't seem to have fixed anything.

We should double check the links above for more information and try to find out a more efficient way to use it so we can prevent those leaks from happening. Maybe we're missing some option in the configuration object that could help fixing this issue.

Posible solutions

Probably we should find a way to cache the schemas, as mentioned here in the docs. What we currently have forces the schemas to be re-compiled everytime we call either validateResponse or validateRequest, which could be pretty unefficient, specially on APIs with a large amount of them and / or that receive a lot of requests.

It may be convenient to expose a new method in charge of generating the compiled schema, and modify validateResponse and validateRequest to receive the result as a parameter. This way we could avoid re-compiling the data everytime we want to perform a validation. After all, the content of the schema is not gonna change on run time, meaning it should be enough by compiling it once.

@LonelyPrincess LonelyPrincess added the bug Something isn't working label Feb 2, 2022
@LonelyPrincess LonelyPrincess self-assigned this Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
1 participant