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

Option to limit memory usage #211

Closed
Le0Developer opened this issue May 7, 2022 · 3 comments · Fixed by #212
Closed

Option to limit memory usage #211

Le0Developer opened this issue May 7, 2022 · 3 comments · Fixed by #212
Milestone

Comments

@Le0Developer
Copy link
Contributor

I'd love to see an option to limit the max memory usage of a single LuaRuntime.

Lua supports passing a custom allocator function to lua_newstate which could refuse to allocate more memory when the limit is reached.

An example of this can be found here on stackoverflow.

@Le0Developer
Copy link
Contributor Author

Currently implementing this in my fork and I stumpled over 2 problems:

  • max_memory < ~2kb causes a Failed to initialise Lua runtime error (expected)
  • max_memory < 24kb causes a lua panic by lua.luaL_openlibs(L)
  • max_memory < 24440b causes a segmentation fault by set_overflow_handler

So max_memory between 2kb-24.5kb causes some not very nice bugs.

@scoder
Copy link
Owner

scoder commented May 8, 2022

Sounds like a great idea.

We could probably avoid initialisation time crashes by disabling the limitation until the Lua runtime is initialised. I think that's a fair thing to do: apply the limit only to memory that the user can control, not something that Lupa needs.

@Le0Developer
Copy link
Contributor Author

Sounds good, I'll finish writing tests and then work on that.

@scoder scoder added this to the 2.0 milestone Aug 7, 2022
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 a pull request may close this issue.

2 participants