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.52k stars 2.07k forks source link

Segmentation Fault calling native IsPlayerAceAllowed #2547

Open Jamesking56 opened 4 months ago

Jamesking56 commented 4 months ago

What happened?

Sometimes, when calling IsPlayerAceAllowed on the server-side, it crashes the server with a segmentation fault:

=================================================================
        Native Crash Reporting
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
        Managed Stacktrace:
=================================================================
          at <unknown> <0xffffffff>
          at WrapScriptHost:InvokeNative <0x001f2>
          at WrapScriptHost:InvokeNative <0x00209>
          at CitizenFX.Core.ScriptContext:InvokeInternal <0x00084>
          at CitizenFX.Core.ScriptContext:Invoke <0x0005a>
          at CitizenFX.Core.Native.API:InternalIsPlayerAceAllowed <0x0012a>
          at CitizenFX.Core.Native.API:IsPlayerAceAllowed <0x0004a>
          at <>c:<OurMethodTwo>b__5_0 <0x0009a>
          at WhereArrayIterator`1:ToList <0x00134>
          at System.Linq.Enumerable:ToList <0x0012f>
          at OurClassTwo:OurMethodTwo <0x00172>
          at <OurMethodOne>d__11:MoveNext <0x000a8>
          at System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start <0x000a1>
          at OurClassOne:OurMethodOne <0x001fa>
          at System.Timers.Timer:MyTimerCallback <0x001f1>
          at Scheduler:TimerCB <0x001ba>
          at System.Threading.QueueUserWorkItemCallback:System.Threading.IThreadPoolWorkItem.ExecuteWorkItem <0x00086>
          at System.Threading.ThreadPoolWorkQueue:Dispatch <0x003da>
          at System.Threading._ThreadPoolWaitCallback:PerformWaitCallback <0x00082>
          at <Module>:runtime_invoke_bool <0x000a4>
=================================================================

Not sure why this is happening but has started happening since updating our server build to 8102

Expected result

IsPlayerAceAllowed checks aces and returns a successful response

Reproduction steps

We're calling IsPlayerAceAllowed in a ten second interval, so not sure if its related to looping the function that causes it to fail sometimes.

Importancy

Crash

Area(s)

FiveM, FXServer

Specific version(s)

FXServer 8102

Additional information

No response

Mathu-lmn commented 4 months ago

Hey, can you provide the code you're using to reproduce this issue please ?

gottfriedleibniz commented 4 months ago

Not sure why this is happening but has started happening since updating our server build to 8102?

What build were you using prior? Linux stack-traces/dumps are a bit annoying to work with so this may require finding the exact server build in which this started to happen.

Jamesking56 commented 4 months ago

Hey, can you provide the code you're using to reproduce this issue please ?

Code is essentially, every 10 seconds calling IsPlayerAceAllowed for every player to update a list of players for who has a certain ace permisson.

What build were you using prior? Linux stack-traces/dumps are a bit annoying to work with so this may require finding the exact server build in which this started to happen.

We've jumped a couple of times recently from 7716 to 8096 to 8102, only noticed it now in 8102 and the server can run for hours before it segfaults like this

DRAIKDev commented 4 months ago

Hey, can you provide the code you're using to reproduce this issue please ?

Code is essentially, every 10 seconds calling IsPlayerAceAllowed for every player to update a list of players for who has a certain ace permisson.

What build were you using prior? Linux stack-traces/dumps are a bit annoying to work with so this may require finding the exact server build in which this started to happen.

We've jumped a couple of times recently from 7716 to 8096 to 8102, only noticed it now in 8102 and the server can run for hours before it segfaults like this

Why don't you just check when players connect or when need to execute some admistration/ace functions, seems to crack a nut with a sledgehammer, maybe if you have a pool if 300 players and didn't even finished before starting again will hung. And also will consume a lot server side.

Jamesking56 commented 4 months ago

Hey, can you provide the code you're using to reproduce this issue please ?

Code is essentially, every 10 seconds calling IsPlayerAceAllowed for every player to update a list of players for who has a certain ace permisson.

What build were you using prior? Linux stack-traces/dumps are a bit annoying to work with so this may require finding the exact server build in which this started to happen.

We've jumped a couple of times recently from 7716 to 8096 to 8102, only noticed it now in 8102 and the server can run for hours before it segfaults like this

Why don't you just check when players connect or when need to execute some admistration/ace functions, seems to crack a nut with a sledgehammer, maybe if you have a pool if 300 players and didn't even finished before starting again will hung. And also will consume a lot server side.

Yeah I have since removed this code as it clearly needs an overhaul, was written a good few years back by a previous dev. Just wanted to flag though that IsPlayerAceAllowed has the chance to segfault

gottfriedleibniz commented 4 months ago

Yeah I have since removed this code as it clearly needs an overhaul,

A concern here is that your stack trace shows something is causing this execution to happen off the main thread:

System.Threading.ThreadPoolWorkQueue:Dispatch

Trying to gauge whether this is a new regression and if so what FXServer build was it introduced.