Qbox-project / qbx_core

http://qbox-project.github.io
Other
67 stars 152 forks source link

Vehicle spawning irregularities #316

Closed jnccloud closed 3 months ago

jnccloud commented 10 months ago

Summary

Near daily reports of vehicles requested from garage spawning with incorrect plate and missing mods

Reproduction

I have spent over 8 hours trying to reproduce and cannot reproduce locally or from remote server. Players are requesting a personal vehicle from their garage and this will happen sometimes, usually once per day at approx. 15 avg players. Has happened from v1.2+. Cannot verify if happened prior to 1.2.

Expected behavior

The plate to match the vehicle 100% of the time, keys given and mods to always apply to the vehicle.

Actual behavior

In small cases (<5% observed) the plate will not set.

  1. Using qbx_garages or rahe-boosting (I implemented server side vehicle spawn from QBX), a vehicle is created
  2. The vehicle's plate will not match the requested vehicle's plate
  3. User cannot drive vehicle (no keys), and their cosmetics and performance mods are not applied

Additional context

My server is a low pop beta with 10-20 players online when the issue generally occurs.

I created a thread in the Discord with my debugging information as I went through the process: https://discord.com/channels/1012753553418354748/1195501924041117727

There were other issues discovered that were originally believed to be related (same issue happening with job spawns), but I believe those are unrelated now. At least for qbx_ambulancejob, the missing keys/wrong plate is believed to be due to the plate being set on the requestor's client without regard to who the entity owner is. The warning you'd expect is masked because the properties are not set by ox_lib as they are in the core.

I understand without reproduction steps that this is a long shot but it is a very troublesome issue. I will appreciate any suggestions or research into this.

Last Updated

1-12-2023

Custom Resources

Yes but nothing that will interfere with standard vehicle spawning

Resource Rename

No

solareon commented 10 months ago

So looking at this more in depth I think the issue might be coming from this section. https://github.com/Qbox-project/qbx_core/blob/848b20c3eba4228938ba2306b776371093bb6bed/modules/utils.lua#L225-L227

We fire off a net event to trigger the prop change yet we return the netId to prior to knowing if the netevent is completed. Let me put together a draft fix that you could try and see if the issue is fixed.

solareon commented 10 months ago

@jnccloud try using this branch https://github.com/Qbox-project/qbx_core/tree/solareon-vehprops-fix-1 and see if that changes anything. I haven't tested this just theoretical code.

jnccloud commented 10 months ago

Thanks I will try this. With the vehicle plate being set in qbx garage as well as ox lib have any effect on this?

jnccloud commented 10 months ago

Meaning the smoking gun for me was seeing photo evidence of the wrong plate on a car

jnccloud commented 10 months ago

@jnccloud try using this branch https://github.com/Qbox-project/qbx_core/tree/solareon-vehprops-fix-1 and see if that changes anything. I haven't tested this just theoretical code.

I think you forgot the callback. I just see the caller in the utils and new lib module image

solareon commented 10 months ago

Yep sorry I missed that. hitting ctrl+s is fundamental

jnccloud commented 10 months ago

Haha, no problem. So we don't need to call back with OK or the veh ID etc?

solareon commented 10 months ago

Thanks I will try this. With the vehicle plate being set in qbx garage as well as ox lib have any effect on this?

Yes I believe that might be the issue in a roundabout way. In the case where another player is nearby what could be happening is they are identified as the entity owner and then sent the netevent to mangle with the car and all the while the SpawnVehicle() function has returned which executes the rest of the code to fiddle with the car props including the plate and the two are competing for ownership of the entity leading to misconfigured vehicles. ox_lib isn't setting the vehicle plate but is actively messing with the vehicle

Per the ox_lib docs the example shows using a netevent but in the code it says this is a bad idea as shown here - https://github.com/overextended/ox_lib/blob/beec00eded9d3e89ee37fe2095b2cb2f222355e8/resource/vehicleProperties/client.lua#L89-L100

solareon commented 10 months ago

Haha, no problem. So we don't need to call back with OK or the veh ID etc?

Nope, the await in the callback means that it will yield until it's done whatever needed to be done.

jnccloud commented 10 months ago

Yeah I have been studying the code all night, I noticed that too. At least I noticed the issue in the government jobs vehicle spawning. Just need some callbacks instead of relying on the requestor.

Nope, the await in the callback means that it will yield until it's done whatever needed to be done.

Great!

jnccloud commented 10 months ago

image Working locally. I will push this out now and ask people to use their garages as much as possible. Thanks for the help.

solareon commented 10 months ago

yeah try and get people to all stand around near each other and pop out cars

jnccloud commented 10 months ago

FYI - still testing this. May take a few days to get results.

solareon commented 10 months ago

@jnccloud no worries if it crops up please let us know and reopen the issue.

jnccloud commented 10 months ago

@solareon

@jnccloud no worries if it crops up please let us know and reopen the issue.

I don't think I have perms to re-open, but just had it happen again with the PR for core in-place. FWIW, this user is in the UK and the server is in the US.

image image

No errors in server or client console. What's different this time is that the user was stuck in place. Not sure how that happened. They had to relog. But the plate was still wrong on the car.

solareon commented 10 months ago

They were stuck in place due to SpawnVehicle not returning from the callback so his client was waiting for that event to occur. It may have stalled due to whatever entity owner was determined at the time of the callback either left range and the entity owner changed prior to the callback completing. Someone probably got an f8 error but didn't see it.

jnccloud commented 10 months ago

I am collecting logs from everyone right now. Once I get those I'll see if there's anything related.

solareon commented 10 months ago

So I have an idea to try but will require a bit more modification. Let me make another branch and I'll give you some extra steps

uncomment these lines in ox_lib.

https://github.com/overextended/ox_lib/blob/51646698e1f414b3c9d8321020f5775ad8ef6d5e/resource/vehicleProperties/client.lua#L102-L115

and then cherry-pick the changes from this branch. Without the statebag change in ox_lib though this won't work and you won't have any customizations. https://github.com/Qbox-project/qbx_core/tree/solareon-vehprops-statebag

jnccloud commented 10 months ago

@solareon

FYI, we found the offending log:

[   3581766] [b2944_GTAProce]             MainThrd/ ^5[qbx_core] ^3[WARN] setting vehicle properties on non entity owner client. This may cause certain properties to fail to set. entity:  5200642^7

The final timestamp in the log is at 7328906 so I don't think he disconnected at least.

I will look into the changes suggested now

jnccloud commented 10 months ago

I've modified ox_lib and cherry picked those changes. Tested and confirmed my vehicle spawned with properties set. Waiting for feedback from users now.

solareon commented 10 months ago

@solareon

FYI, we found the offending log:

[   3581766] [b2944_GTAProce]             MainThrd/ ^5[qbx_core] ^3[WARN] setting vehicle properties on non entity owner client. This may cause certain properties to fail to set. entity:    5200642^7

The final timestamp in the log is at 7328906 so I don't think he disconnected at least.

I will look into the changes suggested now

@jnccloud the user that had the log error message what is their network latency to the server?

jnccloud commented 10 months ago

@solareon I don't know specifically but its also a UK user so at least 100ms

solareon commented 9 months ago

@jnccloud did you get any feedback positive/negative with the statebag change?

jnccloud commented 9 months ago

@jnccloud did you get any feedback positive/negative with the statebag change?

I haven't had any new reports of the problem reoccurring but my beta player base has dramatically dropped over the past few days.

Manason commented 8 months ago

@solareon Was there ever a PR fix for this to core?

solareon commented 8 months ago

no. im testing this live on my server now but its only been a few days with the statebag loop. @Manason

solareon commented 8 months ago

Testing of the statebag change worked well. I'll put together a PR for it later this afternoon

solareon commented 7 months ago

So it appears there is a corner case for this. If you are warping the player ped into the vehicle being spawned then the entity owner may change while the vehicle props are being set. This can lead to either the props reverting or just failing to be set entirely.

I believe the fix for this maybe to yield returning the netId and entity handle until the the props are cleared if set.

SKITTLE6969 commented 6 months ago

weird thing is even i also experience the same thing but it is so random that i'm unable to recreate it but happens to alot of other players vehicles. I do not use the warp in as well so that it wont interfere with the entity owner yet i get atleast 3-4 reports saying vehicle mods are completely gone. In most cases i noticed that vehicle sometimes has a delay of spawning on the parking location and its different from player to player as well, some get the vehicle spawned instantly and some has a delay for about 3-5 seconds.

Manason commented 3 months ago

This should be fixed as of v1.16.0