fivem icon indicating copy to clipboard operation
fivem copied to clipboard

An infinite while loop with SetTimeout causing Operating System(Linux) to Crash

Open Luke20201 opened this issue 8 months ago • 4 comments

What happened?

  • Used the following code
CreateThread(function()
  while true do 
              SetTimeout(1, function()
                  -- do something here, I called a function when doing it
              end)
          end
end)
  • OS Ram spikes to 100% almost immediately
  • Device crashes and requires reboot

Expected result

FXServer / TXadmin to catch the issue and terminate before this happens. If using an infinite while loop without SetTimeout, FXServer reboots.

Reproduction steps

Run the following in a server script

CreateThread(function()
  while true do 
              SetTimeout(1, function()
                  -- do something here, I called a function when doing it
              end)
          end
end)

Importancy

Crash

Area(s)

FXServer

Specific version(s)

FiveM b14158

Additional information

No response

Luke20201 avatar May 01 '25 18:05 Luke20201

Error 40 detected

mickeygeecom avatar May 02 '25 14:05 mickeygeecom

This doesn't seem like an actual issue, you're infinitely looping, this would be expected behavior.

It's more curious that you managed to actually crash your system running this, since most machines should handle something like this pretty well (for Linux when it got close to maxing out the memory it OOM killed it)

AvarianKnight avatar May 02 '25 14:05 AvarianKnight

This doesn't seem like an actual issue, you're infinitely looping, this would be expected behavior.

It's more curious that you managed to actually crash your system running this, since most machines should handle something like this pretty well (for Linux when it got close to maxing out the memory it OOM killed it)

I'm only reporting it because it caused an OS crash. Considering FXServer just reboots when using an infinite while loop, I would expect it not doing the same for SetTimeout is a bug

Luke20201 avatar May 02 '25 14:05 Luke20201

The OS crashing is from you running out of memory, not from something that FXServer is doing, so I still don't think this is an Cfx issue, more-so an issue with how your OS is handling a process using too much memory. As said before on Linux this reproduction will use a lot of ram and max out the CPU core, but when it uses too much memory the Linux OOM killer, kills the process.

Image

AvarianKnight avatar May 02 '25 15:05 AvarianKnight