lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> On Nov 27, 2018, at 4:12 PM, Philippe Verdy <verdy_p@wanadoo.fr> wrote:
> 
> This example is "blocking" all threads, but does not use recursion or reentrance.
> 
> 
>   while true do
>     local x={}
>     setmetatable(x, mt)
>   end
> 
> It will allocate an infinite number of new objects that will never be finalized. This thread will exhaust rapidly all resources allowed by the OS for the process, possibly allocating gigabytes or more that will never be used and will constantly grow the finalization list. The CPU will be running at 100%, with lot of paging to disk, causing severe problems to the host OS if the Lua host process is not given hard limits using the OS API (if not, the OS will finally hang and probably crash: this gives then a successful DOS attack). But if we can force a __gc to not finalize the object immediately by putting it in a "delay" list that will be marked as noit finalizable and will remain reachable, we can limit the frequency for finalization of these objects.

  t = {}
   while true do
       table.insert(t, “foo”)
   end

So does this code. So do any number of similar run-away blocks of code. What is so special about your example that it should be prevented, when simple examples like mine can do the same thing?

—Tim