alliedmodders / amxmodx

AMX Mod X - Half-Life 1 Scripting and Administration
http://www.amxmodx.org/
494 stars 197 forks source link

SQL_ThreadQuery hangs the server when changing the map #867

Open Nelpsen opened 4 years ago

Nelpsen commented 4 years ago

The server starts to wait, when the queue from the accumulated SQL_ThreadQuery will be completed or will not be timed out, if the database is unavailable, the server will freeze and will wait.

There is no such problem in sourcemod, the card change does not wait for the queue to end, and after the card change the queue continues to try to send requests.

AMXModX 1.9.0

xLeviNx commented 4 years ago

The server starts to wait, when the queue from the accumulated SQL_ThreadQuery will be completed or will not be timed out, if the database is unavailable, the server will freeze and will wait.

There is no such problem in sourcemod, the card change does not wait for the queue to end, and after the card change the queue continues to try to send requests.

AMXModX 1.9.0

I'm pretty sure Source mod does the same thing if the database is unavailable. Can confirm its happened when we switched hosts and had to wait for our databases to migrate.

This is normal behavior, honestly don't see a solution or method to fix this.

Nelpsen commented 4 years ago

The server starts to wait, when the queue from the accumulated SQL_ThreadQuery will be completed or will not be timed out, if the database is unavailable, the server will freeze and will wait. There is no such problem in sourcemod, the card change does not wait for the queue to end, and after the card change the queue continues to try to send requests. AMXModX 1.9.0

I'm pretty sure Source mod does the same thing if the database is unavailable. Can confirm its happened when we switched hosts and had to wait for our databases to migrate.

This is normal behavior, honestly don't see a solution or method to fix this.

Do not wait for the completion of the request queue at the time of the card change, but continue to execute the queue after the card is changed.

SmileYzn commented 4 years ago

What query your plugin is running? You can explain better? To be honest i think that can be fixed using other moment to save the data than map change.

Nelpsen commented 4 years ago

What query your plugin is running? You can explain better? To be honest i think that can be fixed using other moment to save the data than map change.

The status of the players is updated during disconnect, the disconnect of all players is triggered when the card is changed. If the database is unavailable, the server will wait for the queue to complete.

The workaround was to change the mysql_timeout cvar to 5 seconds.

There is a small fix for the module; when a card is changed, the queue is recorded temporarily in a file and, after its change, continues to attempt execution.

SmileYzn commented 4 years ago

It was what I was going to suggest. Anyway SQL do not have a better design to save players data.

SmileYzn commented 4 years ago

Are you sure that you are not missed thread query with Execute's(which are blocking)? Can you provide any examples?

If you run SQL_ThreadQuery in plugin_end event, server will hang until the query return results to handler.

afwn90cj93201nixr2e1re commented 4 years ago

Ok, im gonna check, im pretty sure that u are wrong.

afwn90cj93201nixr2e1re commented 4 years ago

@SmileYzn ok, u are right, yes, external sleep on mysql causing server also stop working (on mapchanges only, yes) (not actualy stoped, just slept for 20 seconds)...

That's strange. So, we need to implement SQL_ThreadQuery2 for real non-blocking, but rn SQL_ThreadQuery fixing problem that when we close connection (on server deactivate post) on mysql queries in queues also dropped without execution. But actually they aren't blocking on nonmap changes as u said, it's ok for me, just ask dvander for some suggestions, idk, he implemented this.

SmileYzn commented 4 years ago

SQL_ThreadQuery is just based on ServerFrame also some code on OnPluginsUnloading, while this is there, can't be "fixed".

dvander commented 4 years ago

AMX Mod X unloads plugins on map change, which means flushing database queues. SourceMod persists plugins across maps. You'd see the same problem on SourceMod if you tried to unload the plugin.

Probably the only option here would be to specify that some queries are allowed to complete with no feedback (eg if it succeeds or fails, the plugin would never know).