citizenfx / fivem

The source code for the Cfx.re modification frameworks, such as FiveM, RedM and LibertyM, as well as FXServer.
https://cfx.re/
3.54k stars 2.08k forks source link

AddStateBagChangeHandler #2413

Open KiLaF opened 7 months ago

KiLaF commented 7 months ago

What happened?

so when their is a rate limit that is putten on state bags that stop makes you barelly can use it when their is multiple players doing so in the same time. I tried to use state bag to make a contact with the serveur but when im the only connected it works but when multiple players it kicks them of overflow

Expected result

Reduce ratelimit or fix

Reproduction steps

i explained everything up

Importancy

Security issue

Area(s)

FiveM

Specific version(s)

FiveM

Additional information

No response

AvarianKnight commented 7 months ago

Its very hard to understand what you're saying. Can you provide example code of how you're hitting the state packet overflow

KiLaF commented 7 months ago

Its very hard to understand what you're saying. Can you provide example code of how you're hitting the state packet overflow

I wanted to use it for a contact between client & server instead of TriggerServerEvent

thorium-cfx commented 7 months ago

Reading your explanation I understand that when you enable rate limiting on state bags, you quickly hit the rate limiting limits, correct?

mcNuggets1 commented 7 months ago

"Enable rate limiting" There is rate limiting?

thorium-cfx commented 7 months ago

There is rate limiting?

Yep, I'll leave that to @nihonium-cfx and @AvarianKnight, not sure if they already made public documentation on it

AvarianKnight commented 7 months ago

There's where a few rate limiters for state bags, they use the same logic as client->server net events.

Each rate limiter can be adjusted via ConVar if you're hitting the rate limits, though these limits are extremely high for defaults and if you're hitting them then I highly recommend you adjust how you're sending them.

These limiters are needed to prevent the possibility of memory exhaustion or to prevent a client from crashing the server you can find more information in https://github.com/citizenfx/fivem/issues/2361

Regular State Bag Limiter

Flood State Bag Limiter

If a client is detected as flooding then they will be dropped from the server so that they don't cause any network issues.

Size State Bag limiter

If a client is detected to be sending too large packets then the server will automatically drop them to prevent them from overloading the network thread and to prevent the possibility of memory exhaustion.

For reference these are the values we run on our server

# the client rarely sets state bags so this value should be extremely low
set rateLimiter_stateBag_rate 20
set rateLimiter_stateBag_burst 30

# setting this to 0 will cause a server assert
set rateLimiter_stateBagFlood_rate 1
set rateLimiter_stateBagFlood_burst 1

# clients should never sync large state to the server
# set rateLimiter_stateBagSize_rate 16000
# set rateLimiter_stateBagSize_burst 18000