BUG - Strange behavior with threads and wait

First of all, hello and I hope that you are having a nice day !

1. Client (production/canary) and FXServer version :
Client : Canary and production Ver 5134
FXServer : Linux 5134 (Game build 2545, also tested on game build 1604)

2. What you expected to happen
The resource to not consume anything after the repro command

3. What actually happens
There seem to be an issue when a thread / event has a Wait inside of it (with any duration). The resource will start having spikes of CPU consumption every one or two seconds for no reasons?

4. Category of bug (eg. client, server, weapons, peds, native)
Functions with Wait / CreateThread

5. Reproducible steps, preferably with example script(s)
Make a command inside of a client script :

RegisterCommand("repro", function(source, args, rawCommand)
    Wait(0)
    for i = 1, 100 do
        local playerPed = PlayerPedId()
        local coords = GetEntityCoords(playerPed)
        SetEntityCoordsNoOffset(playerPed, coords.x, coords.y, coords.z, false, false, false)
    end
end)

This ridiculous for loop is used to make a lot of native calls for the spikes to be visible with the repro, with fewer native call we still see the Time % have spikes, but it is less significant.
repro.zip (731 Bytes)

Here is how the CPU consumptions of the resource evolve :
Before anything :
image
After command repro :
image
image

Video of the repro :

If you remove the Wait(0) from the repro, you’ll see that the issue reported here will not occur.


I discovered this issue while looking at my resmon and seeing some resources having those spikes, resources that have no infinite thread and only exports / event and should not consume anything. One (modified version of skinchanger, which call a lot of natives in a small amount of time to load the player skin) even has spikes of 0.20 ms every one or two seconds.


I hope that I detailed this report enough.

1 Like

Duplicate and doesn’t actually ‘consume’ anything, just resmon showing incorrect (i.e. not clearing) info if no code is running in a resource anymore.

Resource CPU time spikes (canary) · Issue #1171 · citizenfx/fivem · GitHub (comment)