alliedmodders / sourcemod

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

DHooks/ SDKHooks extensions - Crash @exit #1913

Open ClaudiuHKS opened 1 year ago

ClaudiuHKS commented 1 year ago

The game server crashes if the DHooks or SDKHooks extensions are loaded, even without having any plugins ON, when typing quit into the game server's console.

ambaca commented 1 year ago
meta version
sm version
meta list
sm exts list
sm plugins list
ClaudiuHKS commented 1 year ago

meta version

 Metamod:Source Version Information
    Metamod:Source version 1.12.0-dev+1165
    Plugin interface version: 16:14
    SourceHook version: 5:5
    Loaded As: GameDLL (gameinfo.txt)
    Compiled on: Dec 20 2022 13:35:42
    Built from: https://github.com/alliedmodders/metamod-source/commit/63c5c15
    Build ID: 1165:63c5c15
    http://www.metamodsource.net/

meta list

Listing 7 plugins:
  [01] Hattrick Game Server Manager (Jan 29 2023) by Hattrick HKS
  [02] SourceMod (1.12.0.6974) by AlliedModders LLC
  [03] Stripper (1.2.2) by BAILOPAN
  [04] DHooks (1.12.0.6974) by AlliedModders LLC
  [05] SDK Tools (1.12.0.6974) by AlliedModders LLC
  [06] SDK Hooks (1.12.0.6974) by AlliedModders LLC
  [07] CS Tools (1.12.0.6974) by AlliedModders LLC

sm version

 SourceMod Version Information:
    SourceMod Version: 1.12.0.6974
    SourcePawn Engine: 1.12.0.6974, jit-x86 (build 1.12.0.6974)
    SourcePawn API: v1 = 5, v2 = 16
    Compiled on: Jan 29 2023 12:26:26
    Built from: https://github.com/alliedmodders/sourcemod/commit/30a21608
    Build ID: 6974:30a21608
    http://www.sourcemod.net/

sm exts list

[SM] Displaying 14 extensions:
[01] Automatic Updater (1.12.0.6974): Updates SourceMod gamedata files
[02] Webternet (1.12.0.6974): Extension for interacting with URLs
[03] BinTools (1.12.0.6974): Low-level C/C++ Calling API
[04] Client Preferences (1.12.0.6974): Saves client preference settings
[05] MySQL-DBI (1.12.0.6974): MySQL driver implementation for DBI
[06] PostgreSQL-DBI (1.12.0.6974): PostgreSQL driver implementation for DBI
[07] SQLite (1.12.0.6974): SQLite Driver
[08] DHooks (1.12.0.6974): Dynamic Hooks
[09] SDK Tools (1.12.0.6974): Source SDK Tools
[10] SDK Hooks (1.12.0.6974): Source SDK Hooks
[11] CS Tools (1.12.0.6974): CS extended functionality
[12] GeoIP (1.12.0.6974): Geographical IP information
[13] Regex (1.12.0.6974): Provides regex natives for plugins
[14] Top Menus (1.12.0.6974): Creates sorted nested menus

sm plugins list

[SM] No plugins loaded

OK, you got me. @ambaca, it only crashes when the DHooks extension is in use or when the SDKHooks extension is in use. If any of addons/sourcemod/extensions/dhooks.autoload or addons/sourcemod/extensions/sdkhooks.autoload exists, even having 0 plugins ON, when I type quit into the game server's console, it spawns a memory dump and the exit process takes much more time.

peace-maker commented 1 year ago

Are you running on windows or linux?

ClaudiuHKS commented 1 year ago

Are you running on windows or linux?

Windows 11.

peace-maker commented 1 year ago

I can't reproduce a crash on a CS:GO server running the same metamod and sourcemod versions as you are on Windows 10. Can't test on Windows 11. Can you upload a minidump of the crash or attach a debugger before exiting the server to see where it crashes?

ClaudiuHKS commented 1 year ago

I can't reproduce a crash on a CS:GO server running the same metamod and sourcemod versions as you are on Windows 10. Can't test on Windows 11. Can you upload a minidump of the crash or attach a debugger before exiting the server to see where it crashes?

srcds.exe.9404.zip

peace-maker commented 1 year ago

Hm, it looks like there's a heapoverflow somewhere which crashes while destroying a global CUtlVector allocation on exit in the server.dll. I'm not sure why that doesn't happen on my test server. It might be related to the map or other config?

ClaudiuHKS commented 1 year ago
Unhandled exception at 0x7AF3D889 (tier0.dll) in srcds.exe.38096.dmp: 0xC0000005: Access violation reading location 0xADB4ED58.

I tried without server.cfg and without any other metamod plugins BUT sourcemod. Also tried on de_mirage (old = fy_snow). Same thing. If you still can't find anything suspect regarding SDKHooks/ DHooks then maybe it's just a problem that fires on Windows 11 only. My srcds.exe launch options were and are -usegh +usegh -usercon +usercon -hushasserts +hushasserts -threads 8 +threads 8 -high +high -console +console -game csgo +game csgo -map fy_snow +map fy_snow -maxplayers 512 +maxplayers 512 -maxplayers_override 512 +maxplayers_override 512 -tickrate 512 +tickrate 512 -port 1337 +port 1337 -hostport 1337 +hostport 1337 -secure +secure -game_type 0 +game_type 0 -game_mode 1 +game_mode 1 -exec server +exec server -mapcyclefile 1337.txt +mapcyclefile 1337.txt (the 512 things will be clamped to their max anyways). However I don't really think that a command line might influence how SDKHooks/ DHooks detach. 1 more thing that I altered is gameinfo.txt. My game server is on G:\SteamCMD\steamapps\common\Counter-Strike Global Offensive Beta - Dedicated Server (TESTING) but the original installation path is G:\SteamCMD\steamapps\common\Counter-Strike Global Offensive Beta - Dedicated Server. So updated gameinfo.txt as below.

        SearchPaths
        {
            GameBin |gameinfo_path|addons/metamod/bin/linux64
            GameBin |gameinfo_path|addons/metamod/bin/win64
            GameBin |gameinfo_path|addons/metamod/bin
            GameBin |gameinfo_path|bin
            Game |gameinfo_path|.
            Game csgo
            Game "g:/steamcmd/steamapps/common/counter-strike global offensive beta - dedicated server/csgo"
        }

The (TESTING) one just doesn't have /csgo/*.vpk files in it. I will also try this on the original installation without gameinfo.txt link between two game servers to see if still happening.

EDIT 1 Tested without custom fallback game path (without Game "g:/steamcmd/steamapps/common/counter-strike global offensive beta - dedicated server/csgo") and still crashes. No matter what I do, it always crashes if SDKHooks/ DHooks is in use. Well, maybe it really is a Windows 11 issue, no idea.

EDIT 2 I hope you checked C:\Users\YourUserName\AppData\Local\CrashDumps because the memory dump isn't created into the same location with srcds.exe.

peace-maker commented 1 year ago

EDIT 2 I hope you checked C:\Users\YourUserName\AppData\Local\CrashDumps because the memory dump isn't created into the same location with srcds.exe.

I attached a debugger and exited the server and it didn't catch any exception. If you're up to it, you could install visual studio for c++ development and attach to the running process. Maybe you'll be able to see which CUtlVector was corrupted.

bakugo commented 1 year ago

I'm experiencing a somewhat similar crash on Linux that happens whenever I exit while a player is on the server with a virtual dhook active (doesn't happen for all hooks, but happens reliably with a specific simple plugin I have)

#0  0xded458de in ?? () from bin/crashhandler.so
#1  <signal handler called>
#2  0xeaef5130 in SourceHook::CPageAlloc::Free(void*) ()
   from /home/bakugo/srcds-tf2/tf/addons/metamod/bin/metamod.2.tf2.so
#3  0xeaef6060 in SourceHook::Impl::GenContext::~GenContext() ()
   from /home/bakugo/srcds-tf2/tf/addons/metamod/bin/metamod.2.tf2.so
#4  0xeaefd0ff in SourceHook::Impl::CHookManagerAutoGen::~CHookManagerAutoGen() ()
   from /home/bakugo/srcds-tf2/tf/addons/metamod/bin/metamod.2.tf2.so
#5  0xf7cb181d in __cxa_finalize () from /lib/i386-linux-gnu/libc.so.6
#6  0xeaee6a43 in __do_global_dtors_aux () from /home/bakugo/srcds-tf2/tf/addons/metamod/bin/metamod.2.tf2.so
#7  0xf7ecd152 in ?? () from /lib/ld-linux.so.2
#8  0xf7de54b4 in _dl_catch_exception () from /lib/i386-linux-gnu/libc.so.6
#9  0xf7ecd615 in ?? () from /lib/ld-linux.so.2
#10 0xf7ece127 in ?? () from /lib/ld-linux.so.2
#11 0xf7de544b in _dl_catch_exception () from /lib/i386-linux-gnu/libc.so.6
#12 0xf7de5524 in _dl_catch_error () from /lib/i386-linux-gnu/libc.so.6
#13 0xf7ee5b6c in ?? () from /lib/ld-linux.so.2
#14 0xf7cf8c6a in ?? () from /lib/i386-linux-gnu/libc.so.6
#15 0xf7cf8964 in dlclose () from /lib/i386-linux-gnu/libc.so.6
#16 0xeaf2b1cc in mm_UnloadLibrary(void*) () from /home/bakugo/srcds-tf2/tf/addons/metamod/bin/server.so
#17 0xeaf2900f in mm_UnloadMetamodLibrary() () from /home/bakugo/srcds-tf2/tf/addons/metamod/bin/server.so
#18 0xeaf2aac3 in ServerPlugin::Unload() () from /home/bakugo/srcds-tf2/tf/addons/metamod/bin/server.so
#19 0xf65245cc in CPlugin::Unload() () from /home/bakugo/srcds-tf2/bin/engine_srv.so
#20 0xf6524a69 in CServerPlugin::UnloadPlugins() () from /home/bakugo/srcds-tf2/bin/engine_srv.so
#21 0xf651b6bf in SV_ShutdownGameDLL() () from /home/bakugo/srcds-tf2/bin/engine_srv.so
#22 0xf65312e2 in CModAppSystemGroup::Main() () from /home/bakugo/srcds-tf2/bin/engine_srv.so
#23 0xf657be08 in CAppSystemGroup::Run() () from /home/bakugo/srcds-tf2/bin/engine_srv.so
#24 0xf6531fcd in CDedicatedServerAPI::ModInit(ModInfo_t&) () from /home/bakugo/srcds-tf2/bin/engine_srv.so
#25 0xf721d493 in CDedicatedAppSystemGroup::Main() () from bin/dedicated_srv.so

Could it be caused by the same thing, or should I open another issue for this?

KyleSanderson commented 1 year ago

You've left out the (second 😄) critical piece which is the STR. Thank you for the backtrace.

Exit crashes are tricky, so while it could be related (same players involved), it might not be (different OS and Game). As both are around dhooks, let's keep them in the same issue for now. Can you please provide the sample plugin that invokes the crash and the steps that cause it on a clean server with the plugin and nothing else.

bakugo commented 1 year ago

plugin.zip

Running this plugin (with no other plugins or non-default extensions) seems to cause it every time when exiting if at least one player is in-game. (it's for TF2 btw)