brouznouf / fivem-mysql-async

MySql Async Library for FiveM
MIT License
111 stars 106 forks source link

Transactions broken (DONT USE WILL CRASH MYSQL CONNECTION) #129

Closed benzon closed 4 years ago

benzon commented 4 years ago

Hi,

Tryed out the MySQL Transaction with latest version, and it's not fixed it's utterly broken.

Testet with following code.

SaveStorageMySQL = function()
    -- Create sqls table
    local sqls = {}

    -- Add each player save query and params to the two tables
    for k, v in ipairs(save) do
        local query = 'UPDATE drp_storage SET type = @type, sid = @sid, data = @data WHERE type = @type and sid = @sid'
        local parameters = {
            ['@type'] = v.type,
            ['@sid'] = v.sid,
            ['@data'] = json.encode(storage[v.type][v.sid])
        }
        table.insert(sqls, {
            query = query,
            parameters = parameters
        })
    end

    -- Execute the transaction
    MySQL.Async.transaction(sqls, cb)
end

The Save works, but if the resource is restartet a couple of times it locks up fully, and even normal MySQL connections from the fxserver wont work unless fx is restartet.

benzon commented 4 years ago

Not sure why transaction ends up locking up MySQL 100% but ye there is a issue with this.

ghost commented 4 years ago

Cannot reproduce that locally. Doing multiple transactions works fine for me.

Can you create a minimum working example, so i have the chance of reproducing your issue?

benzon commented 4 years ago

Did you remember to try and restart the resource a couple of times ? 5-10 times and suddenly it locks up.

benzon commented 4 years ago

Only test code i got is a script im working on, would not mind sharing it with you, but dont wanna share it with the world not right now adleest.

But tryed to use transactions for saving but if i restart it a couple of times it ends in a lock up.

benzon commented 4 years ago

If i revert over to normal Async calls to save the date no lock up on several restarts of the resource.

ghost commented 4 years ago

With the next version it will be fixed. You can run

npm i && npm run build with node.js installed in the source folder to get a development build.

benzon commented 4 years ago

Sounds good, so there was a flaw in the code ? nice that it got fixed.

ghost commented 4 years ago

https://github.com/brouznouf/fivem-mysql-async/issues/129#issuecomment-632946065

That comment made it so i could reproduce the issue, meaning i could see myself what was wrong, from which on it was really easy to fix.

If you have an issue, and tell me how i can trigger it myself, I can actually fix stuff; and that often really quickly if it is important broken stuff.

Sadly nobody does that when reporting an issue. I might have a hunch where stuff is wrong in some cases, but with limited time, I often do not have the time to look in detail.

e.g. the high tick rate people, it is likely their server is just overloaded with resources, sending data between resources eats up a budget. Like at some point your pc cannot be faster. Since mysql-async sends data on the next tick, it often looks like the culprit when it is not.