fivem icon indicating copy to clipboard operation
fivem copied to clipboard

AddStateBagChangeHandler

Open KiLaF opened this issue 11 months ago • 6 comments

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

KiLaF avatar Mar 08 '24 00:03 KiLaF

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

AvarianKnight avatar Mar 08 '24 00:03 AvarianKnight

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

KiLaF avatar Mar 09 '24 14:03 KiLaF

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

thorium-cfx avatar Mar 25 '24 09:03 thorium-cfx

"Enable rate limiting" There is rate limiting?

mcNuggets1 avatar Mar 25 '24 10:03 mcNuggets1

There is rate limiting?

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

thorium-cfx avatar Mar 25 '24 10:03 thorium-cfx

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

  • rateLimiter_stateBag_rate default value 75 - the amount of state bag change packets that can be sent per second
  • rateLimiter_stateBag_burst default value 125 - the amount that the rate limiter can burst to before hitting the limiter, after hitting this limiter the client will be blocked from changing any state bags for the next second.

Flood State Bag Limiter

  • rateLimiter_stateBagFlood_rate default value 150 - the amount of requests that can be sent per second before it being considered a "flood".
  • rateLimiter_stateBagFlood_burst default value 175 - the amount of requests that the limiter can burst to before hitting the flood kick.

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

  • rateLimiter_stateBagSize_rate default value is 131,072 - the size limit of the packets per 1 second
  • rateLimiter_stateBagSize_burst default value is 262,144 - the size burst limit of the packets per 1 second

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

AvarianKnight avatar Mar 25 '24 12:03 AvarianKnight