alliedmodders / sourcemod

SourceMod - Source Engine Scripting and Administration
http://www.sourcemod.net/
987 stars 423 forks source link

Threaded SQL queries lead to freezes and crashes on plugin unloading #1647

Open Alexeyt89 opened 2 years ago

Alexeyt89 commented 2 years ago

Help us help you

Environment

Description

I found this issue when was investigating random crashes on map change on a CSGO server. It turned out that the reason was a "reloader" plugin which would reload all smx plugins on map change. Another reason was unstable connection to the database server which was used by some of the plugins. The server would crash 1-2 times a day. I guess, if a plugin is reloaded while it is executing a threaded SQL query, the query is turned into non-threaded and, if the query can't be executed because of communication problems with the database, it freezes the server. On adding the example plugin to one of my servers it crashes after a few seconds without any information in the crash stack, but I suppose that the watchdog kills it, another server just freezes for 30 seconds. If my assumption is correct, to solve this problem I would suggest:

If these are not the ways, it would be nice to have some information about such crashes in the logs. The root of the problem as I can see is in function DBManager::OnPluginWillUnload.

Make sure the database address in the server configuration is INcorrect before running the example: DBCrashTest.zip

To reproduce the problem: 1) Start the plugin. 2) Wait till it shows the MySQL connection problem message. 3) Reload it two times in a row before it shows the MySQL connection problem message -> the server crashes in 15 seconds.

For convenience I added ServerCommand from the reloader plugin for automatic plugin reloading, but in my case it mostly leads to 30sec freezes.

Headline commented 2 years ago

Hi! Thanks for opening this issue.

Do you happen to have an accelerator link for the crash?

Alexeyt89 commented 2 years ago

Here is what accelerator generates when such crashes happen crashstack.zip 1 dbi.mysql.ext.so + 0x53276