Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fixed the deletion of ConVar/ConCommand not managed by Source.Python.#426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
CookStar wants to merge1 commit intoSource-Python-Dev-Team:master
base:master
Choose a base branch
Loading
fromCookStar:concommand_fix

Conversation

@CookStar
Copy link
Contributor

The function ConVar_Unregister unregisters all ConVar/ConCommand and should not be used.

Output:

plugin_printLoaded plugins:---------------------0:      "Source.Python, (C) 2012-2021, Source.Python Team."1:      "Metamod:Source 1.11.0-dev+1145"---------------------meta version Metamod:Source Version Information    Metamod:Source version 1.11.0-dev+1145    Plugin interface version: 16:14    SourceHook version: 5:5    Loaded As: Valve Server Plugin    Compiled on: Jul 11 2021 22:32:15    Built from: https://github.com/alliedmodders/metamod-source/commit/0bb53f2    Build ID: 1145:0bb53f2    http://www.metamodsource.net/plugin_unload sourcepython[Source.Python] Unloading...[Source.Python] Unloaded successfully.Unloaded plugin "sourcepython"plugin_printLoaded plugins:---------------------0:      "Metamod:Source 1.11.0-dev+1145"---------------------meta versionUnknown command "meta"

to

plugin_unload sourcepython[Source.Python] Unloading...[Source.Python] Unloaded successfully.Unloaded plugin "sourcepython"plugin_printLoaded plugins:---------------------0:      "Metamod:Source 1.11.0-dev+1145"---------------------meta version Metamod:Source Version Information    Metamod:Source version 1.11.0-dev+1145    Plugin interface version: 16:14    SourceHook version: 5:5    Loaded As: Valve Server Plugin    Compiled on: Jul 11 2021 22:32:15    Built from: https://github.com/alliedmodders/metamod-source/commit/0bb53f2    Build ID: 1145:0bb53f2    http://www.metamodsource.net/

@jordanbriere
Copy link
Contributor

jordanbriere commentedOct 10, 2021
edited
Loading

ConVar_Unregister only unregistersConCommandBase that matches our DLL identifier. The one that was generated when we initialized our accessor there:

voidInitServerCommands()
{
ConVar_Register(0, &g_ConVarAccessor);
}

In fact, it works just as it should on my side:

plugin_printLoaded plugins:---------------------0:      "Source.Python, (C) 2012-2021, Source.Python Team."1:      "Metamod:Source 1.11.0-dev+1145"---------------------metaMetamod:Source Menuusage: meta <command> [arguments]  alias        - List or set an alias  clear        - Unload all plugins forcefully  cmds         - Show plugin commands  cvars        - Show plugin cvars  credits      - About Metamod:Source  force_unload - Forcefully unload a plugin  game         - Information about GameDLL  info         - Information about a plugin  list         - List plugins  load         - Load a plugin  pause        - Pause a running plugin  refresh      - Reparse plugin files  retry        - Attempt to reload a plugin  unload       - Unload a loaded plugin  unpause      - Unpause a paused plugin  version      - Version informationspA sub-command is required:  sp auth <sub-command>                     Authorization specific commands.  sp credits                                List all credits for Source.Python.  sp delay <delay:float> <command> [*args]  Execute a command after a given delay.  sp docs <sub-command>                     Documentation specific commands.  sp dump <sub-command>                     Dump various data to files.  sp help [command=None]                    Print all sp sub-commands or help for a    [*server_sub_commands]                    specific command.  sp info                                   Print information about OS, SP and                                              installed plugins.  sp plugin <sub-command>                   Plugin specific commands.  sp update                                 Update Source.Python to the latest                                              version. A restart of the server is                                              required.plugin_unload 0[Source.Python] Unloading...[Source.Python] Restoring old output function...[Source.Python] Resetting cache notifier...[Source.Python] Shutting down python...[Source.Python] Unloading main module...Unloading plugins...Removing entities listener...Unloading auth...[Source.Python] Clearing convar changed listener...[Source.Python] Unhooking all functions...[Source.Python] Clearing all commands...[Source.Python] Unregistering ConVar...[Source.Python] Disconnecting tier2 libraries...[Source.Python] Disconnecting tier1 libraries...[Source.Python] Unloaded successfully.Unloaded plugin "0"metaMetamod:Source Menuusage: meta <command> [arguments]  alias        - List or set an alias  clear        - Unload all plugins forcefully  cmds         - Show plugin commands  cvars        - Show plugin cvars  credits      - About Metamod:Source  force_unload - Forcefully unload a plugin  game         - Information about GameDLL  info         - Information about a plugin  list         - List plugins  load         - Load a plugin  pause        - Pause a running plugin  refresh      - Reparse plugin files  retry        - Attempt to reload a plugin  unload       - Unload a loaded plugin  unpause      - Unpause a paused plugin  version      - Version informationspUnknown command "sp"

@CookStar
Copy link
ContributorAuthor

It only works because your s_nDLLIdentifier happens to be the same as Source.Python's DLL identifier. There is no guarantee that it will work every time.

ConVar_Unregister is a very dumb function. Even if it works correctly, it will only work once.
https://github.com/alliedmodders/hl2sdk/blob/c33f7155e9aff9573c20d86e10c8158425a3d67a/tier1/convar.cpp#L86-L95

@jordanbriere
Copy link
Contributor

It only works because your s_nDLLIdentifier happens to be the same as Source.Python's DLL identifier. There is no guarantee that it will work every time.

But it's not a coincidence. We assign ours_nDLLIdentifier when we callConVar_Register. That ID is ours and ours only. Other binaries that register their accessor will generate their own and set their symbol accordingly. The only issue currently with the registration is that the following calls should be reverted:

voidInitCommands()
{
// Register the say and say_team commands
DevMsg(1, MSG_PREFIX"Registering say and say_team commands...\n");
RegisterSayCommands();
// Register the ConVar accessor.
DevMsg(1, MSG_PREFIX"Registering ConVar accessor...\n");
InitServerCommands();
}
Our accessor should be registered before we registersay andsay_team.

Other than that, It's possible there is a linking issue on Linux and that we ends up sharing the same symbol. If the following assert for you:

fromcvarsimport*assertcvar.find_base('sm').dll_identifierisnotSP_CVAR_DLL_IDENTIFIERassertcvar.find_base('meta').dll_identifierisnotSP_CVAR_DLL_IDENTIFIERassertcvar.find_base('sp').dll_identifierisSP_CVAR_DLL_IDENTIFIER

Then that's likely it. Try to addtier1.a to the excluded libraries:

Set(CMAKE_SHARED_LINKER_FLAGS"${CMAKE_SHARED_LINKER_FLAGS} -Wl,--exclude-libs,libprotobuf.a")

ConVar_Unregister is a very dumb function. Even if it works correctly, it will only work once.

We don't call it multiple times, only on unload, so that isn't really an issue, is it?

Ayuto referenced this pull requestOct 25, 2021
@CookStar
Copy link
ContributorAuthor

CookStar commentedNov 5, 2021
edited
Loading

ConVar and Source SDK is so broken that I feel discouraged.

But it's not a coincidence. We assign ours_nDLLIdentifier when we callConVar_Register. That ID is ours and ours only. Other binaries that register their accessor will generate their own and set their symbol accordingly.

I understand that, but it's not working in practice.

Then that's likely it. Try to addtier1.a to the excluded libraries:

I tried that too, but it doesn't work.

Test Code:

#   CommandsfromcommandsimportConCommandBase#   CvarsfromcvarsimportcvarfromcvarsimportSP_CVAR_DLL_IDENTIFIER#   Memoryfrommemoryimportget_virtual_functionfrommemoryimportmake_objectfrommemory.hooksimportPreHook@PreHook(get_virtual_function(cvar,"RegisterConCommand"))defpre_register_con_command(args):base=make_object(ConCommandBase,args[1])ifnotbase.name:returnprint("RegisterConCommand")print("Name: ",base.name)print("Help Text: ",base.help_text)print("Is Registered: ",base.is_registered())print("Is Command: ",base.is_command())print("Address: ",base._ptr().address)print("dll_identifier: ",base.dll_identifier)print("Is dll_identifier == sp_cvar_dll_identifier: ",base.dll_identifier==SP_CVAR_DLL_IDENTIFIER)

For clarity.
commands/commands_server.cpp

classCPluginConVarAccessor :publicIConCommandBaseAccessor{public:virtualboolRegisterConCommandBase(ConCommandBase* pCommand){printf("[Source.Python] RegisterConCommandBase\n");if (!g_pCVar->FindCommandBase(pCommand->GetName())) {g_pCVar->RegisterConCommand(pCommand);printf("[Source.Python] Registered\n");returntrue;}printf("[Source.Python] Failed\n");returnfalse;}};
Output (CS:GO Linux tier1.a excluded with clarity code)
plugin_load addons/source-python[Source.Python] Loading...[Source.Python] RegisterConCommandBase[Source.Python] Registered[Source.Python] RegisterConCommandBase[Source.Python] Registered[Source.Python] RegisterConCommandBase[Source.Python] Registered[Source.Python] RegisterConCommandBase[Source.Python] Registered[Source.Python] RegisterConCommandBase[Source.Python] Registered[Source.Python] RegisterConCommandBase[Source.Python] Registered[Source.Python] RegisterConCommandBase[Source.Python] Registered[Source.Python] RegisterConCommandBase[Source.Python] Registered[Source.Python] RegisterConCommandBase[Source.Python] Registered[Source.Python] Loaded successfully.Loaded plugin "addons/source-python"sp plugin load test[SP] Loading plugin 'test'...[Source.Python] RegisterConCommandBase[Source.Python] Registered[SP] Successfully loaded plugin 'test'.plugin_printLoaded plugins:---------------------0:      "Source.Python, (C) 2012-2021, Source.Python Team."---------------------plugin_load ../csgo/addons/metamod/bin/server[Source.Python] RegisterConCommandBaseRegisterConCommandName:  metaHelp Text:  Metamod:Source control optionsIs Registered:  FalseIs Command:  TrueAddress:  3813366172dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  True[Source.Python] Registered[Source.Python] RegisterConCommandBase[Source.Python] RegisteredRegisterConCommandName:  metaHelp Text:  Metamod:Source control optionsIs Registered:  TrueIs Command:  TrueAddress:  3813366172dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  True[Source.Python] RegisterConCommandBaseRegisterConCommandName:  metamod_versionHelp Text:  Metamod:Source VersionIs Registered:  FalseIs Command:  FalseAddress:  237287776dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  True[Source.Python] RegisteredRegisterConCommandName:  metamod_versionHelp Text:  Metamod:Source VersionIs Registered:  TrueIs Command:  FalseAddress:  237287776dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  True[Source.Python] RegisterConCommandBaseRegisterConCommandName:  mm_pluginsfileHelp Text:  Metamod:Source Plugins FileIs Registered:  FalseIs Command:  FalseAddress:  234871728dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  True[Source.Python] RegisteredRegisterConCommandName:  mm_pluginsfileHelp Text:  Metamod:Source Plugins FileIs Registered:  TrueIs Command:  FalseAddress:  234871728dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  True[Source.Python] RegisterConCommandBaseRegisterConCommandName:  mm_basedirHelp Text:  Metamod:Source Base FolderIs Registered:  FalseIs Command:  FalseAddress:  235182816dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  True[Source.Python] RegisteredRegisterConCommandName:  mm_basedirHelp Text:  Metamod:Source Base FolderIs Registered:  TrueIs Command:  FalseAddress:  235182816dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  TrueLoaded plugin "../csgo/addons/metamod/bin/server"plugin_printLoaded plugins:---------------------0:      "Source.Python, (C) 2012-2021, Source.Python Team."1:      "Metamod:Source 1.11.0-dev+1145"---------------------metaYou must change the map to activate Metamod:Source.plugin_unload 0[Source.Python] Unloading...[Source.Python] Unloaded successfully.Unloaded plugin "0"spUnknown command "sp"metaUnknown command "meta"plugin_printLoaded plugins:---------------------0:      "Metamod:Source 1.11.0-dev+1145"---------------------
With distributed binaries (CS:GO Linux SP version: 710)
plugin_load addons/source-python[Source.Python] Loading...[Source.Python] Loaded successfully.Loaded plugin "addons/source-python"sp infoIMPORTANT: Please copy the full output.--------------------------------------------------------Checksum      : 6a9c0c874424594cd8a6db604c2701a1Date          : 2021-11-05 05:51:22.111626OS            : Linux-4.15.0-112-generic-x86_64-with-debian-buster-sidGame          : csgoSP version    : 710Github commit : 620d6c39e652a7ab9c928663c094a1d23a38d85eServer plugins:   00: Source.Python, (C) 2012-2021, Source.Python Team.SP plugins:--------------------------------------------------------sp plugin load test[SP] Loading plugin 'test'...[SP] Successfully loaded plugin 'test'.plugin_load ../csgo/addons/metamod/bin/serverRegisterConCommandName:  metaHelp Text:  Metamod:Source control optionsIs Registered:  FalseIs Command:  TrueAddress:  3813808540dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  TrueRegisterConCommandName:  metaHelp Text:  Metamod:Source control optionsIs Registered:  TrueIs Command:  TrueAddress:  3813808540dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  TrueRegisterConCommandName:  metamod_versionHelp Text:  Metamod:Source VersionIs Registered:  FalseIs Command:  FalseAddress:  251280608dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  TrueRegisterConCommandName:  metamod_versionHelp Text:  Metamod:Source VersionIs Registered:  TrueIs Command:  FalseAddress:  251280608dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  TrueRegisterConCommandName:  mm_pluginsfileHelp Text:  Metamod:Source Plugins FileIs Registered:  FalseIs Command:  FalseAddress:  250035296dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  TrueRegisterConCommandName:  mm_pluginsfileHelp Text:  Metamod:Source Plugins FileIs Registered:  TrueIs Command:  FalseAddress:  250035296dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  TrueRegisterConCommandName:  mm_basedirHelp Text:  Metamod:Source Base FolderIs Registered:  FalseIs Command:  FalseAddress:  250119536dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  TrueRegisterConCommandName:  mm_basedirHelp Text:  Metamod:Source Base FolderIs Registered:  TrueIs Command:  FalseAddress:  250119536dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  TrueLoaded plugin "../csgo/addons/metamod/bin/server"plugin_printLoaded plugins:---------------------0:      "Source.Python, (C) 2012-2021, Source.Python Team."1:      "Metamod:Source 1.11.0-dev+1145"---------------------metaYou must change the map to activate Metamod:Source.plugin_unload 0[Source.Python] Unloading...[Source.Python] Unloaded successfully.Unloaded plugin "0"spUnknown command "sp"metaUnknown command "meta"plugin_printLoaded plugins:---------------------0:      "Metamod:Source 1.11.0-dev+1145"---------------------
Switch the plugin load order (CS:GO Linux tier1.a excluded)
plugin_printLoaded plugins:---------------------0:      "Metamod:Source 1.11.0-dev+1145"1:      "Source.Python, (C) 2012-2021, Source.Python Team."---------------------sp infoIMPORTANT: Please copy the full output.--------------------------------------------------------Checksum      : 41b2b930d883739c112f418398fa631eDate          : 2021-11-05 06:22:14.197332OS            : Linux-4.15.0-112-generic-x86_64-with-debian-buster-sidGame          : csgoSP version    : NoneGithub commit : NoneServer plugins:   00: Metamod:Source 1.11.0-dev+1145   01: Source.Python, (C) 2012-2021, Source.Python Team.SP plugins:   00: test--------------------------------------------------------meta load addons/stripper/bin/stripper_mmRegisterConCommandName:  stripper_cfg_pathHelp Text:  Stripper Config PathIs Registered:  FalseIs Command:  FalseAddress:  3958717748dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  TrueRegisterConCommandName:  stripper_current_fileHelp Text:  Stripper for current mapIs Registered:  FalseIs Command:  FalseAddress:  3958717836dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  TrueRegisterConCommandName:  stripper_next_fileHelp Text:  Stripper for next mapIs Registered:  FalseIs Command:  FalseAddress:  3958717924dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  TrueRegisterConCommandName:  stripper_file_lowercaseHelp Text:  Load stripper configs in lowercaseIs Registered:  FalseIs Command:  FalseAddress:  3958718012dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  TrueRegisterConCommandName:  stripper_versionHelp Text:  Stripper VersionIs Registered:  FalseIs Command:  FalseAddress:  3958718900dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  TrueRegisterConCommandName:  stripper_dumpHelp Text:  Dumps the map entity list to a fileIs Registered:  FalseIs Command:  TrueAddress:  3958718988dll_identifier:  11Is dll_identifier == sp_cvar_dll_identifier:  TrueInstallChangeCallback ignoring duplicate change callback!!!Plugin "Stripper" loaded with id 1.meta listListing 1 plugin:  [01] Stripper (1.2.2) by BAILOPANplugin_unload 1[Source.Python] Unloading...[Source.Python] Unloaded successfully.Unloaded plugin "1"spUnknown command "sp"stripper_cfg_pathUnknown command "stripper_cfg_path"

Since this problem affects all ConVars, there is no choice other than to fix it, but#421 and#430 are covered by this problem, which makes things even more complicated.


DevMsg(1, MSG_PREFIX"Unregistering ConVar...\n");
ConVar_Unregister( );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Please replace with:

// See issue #430.// DevMsg(1, MSG_PREFIX "Unregistering ConVar...\n");// ConVar_Unregister( );

@CookStar
Copy link
ContributorAuthor

CookStar commentedDec 3, 2021
edited
Loading

@jordanbriere Can you confirm this issue on your side?

Please replace with:

// See issue #430.// DevMsg(1, MSG_PREFIX "Unregistering ConVar...\n");// ConVar_Unregister( );

Since the root cause of the problem could not be determined, it was neglected, but it's actually not that simple.

fromcvarsimportSP_CVAR_DLL_IDENTIFIERfromcvarsimportcvardefget_bases():bases=list()base=cvar.commandswhilebaseisnotNone:bases.append((base.dll_identifier,base.name,base.is_command()))base=base.nextreturnbasesbases=get_bases()bases.sort(key=lambdax:x[0])forbaseinbases:identifier,name,is_command=baseifidentifier<0oridentifier>=SP_CVAR_DLL_IDENTIFIER:print(identifier,name,is_command)

In this code, you can see if SP_CVAR_DLL_IDENTIFIER overlaps with the dll_identifier of other metamod plugins. If you unload a metamod plugin with overlapping dll_identifier, the ConCommand will be released without being unregistered, causing a segmentation fault in the code as shown earlier(ORfind <string> console command!).

If this is not a Source.Python problem, but a MetaMod problem, I'll just have to apply the earlier fix and see what happens, but causing a clear crash is a problem.

@CookStar
Copy link
ContributorAuthor

CookStar commentedDec 3, 2021
edited
Loading

In my environment, the only way to get around this reliably is to load Source.Python after metamod has finished loading.
Loading with autoexec.cfg is not a workaround for this.

This is just my guess, but it looks like there is a delay in the loading of MetaMod, and Source.Python is catching up and hijacking the ConCommand while MetaMod is loading.

@jordanbriere
Copy link
Contributor

To be honest, I don't think we should care. There is no point into trying to make a non-issue an issue. I mean, so long as loading SM or SP plugins at run-time works, we should not bother if there are issues unloading MM/SM/SP themselves because they can all be fixed with a server reboot and the fact nobody ever reported issues related to this means nobody really does unload and load them on the fly. I'd say make the changes so we know why it was done, and leave it at that. If this becomes a recurrent issue for users then let's address it then.

@CookStar
Copy link
ContributorAuthor

To be honest, I don't think we should care. There is no point into trying to make a non-issue an issue. I mean, so long as loading SM or SP plugins at run-time works, we should not bother if there are issues unloading MM/SM/SP themselves because they can all be fixed with a server reboot and the fact nobody ever reported issues related to this means nobody really does unload and load them on the fly. I'd say make the changes so we know why it was done, and leave it at that. If this becomes a recurrent issue for users then let's address it then.

It's not just a matter of loading/unloading MetaMod/SourceMod/Source.Python itself.
MetaMod supports reloading of MetaMod plugins, and so does SourceMod's Extension system.

The reason this issue is not more obvious is that problems caused by reloading the MetaMod plugin or SourceMod Extension do not lead to an immediate crash, and even if they do, it is not clear how they are related to Source.Python.

@jordanbriere
Copy link
Contributor

It's not just a matter of loading/unloading MetaMod/SourceMod/Source.Python itself.
MetaMod supports reloading of MetaMod plugins, and so does SourceMod's Extension system.

Estimated population that does so: 0.0000005%
Estimated scenarios where we share the same customConVar/ConCommand: 0.00000002%

I know you like to break stuff... 😄 But this is a non-issue in my opinion. At least, not until it becomes one. THere is really no point into focusing on stuff that is unlikely to happens or that never has been reported. If many users come forward and report issues related to this, then it can be addressed at that time but for now, trying to profile and debug this is a waste of time to me,

@CookStar
Copy link
ContributorAuthor

CookStar commentedDec 3, 2021
edited
Loading

At least, not until it becomes one. THere is really no point into focusing on stuff that is unlikely to happens or that never has been reported.

Edited:
This crash is already occurring on other users, it's just not reported here.

then it can be addressed at that time but for now, trying to profile and debug this is a waste of time to me,

I'm working on a fix for the problem in ConVar/ConCommand, I don't know the cause of this problem, but please wait to close this issue as I'm figuring out the workaround.

jordanbriere reacted with confused emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@jordanbrierejordanbrierejordanbriere requested changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@CookStar@jordanbriere

[8]ページ先頭

©2009-2025 Movatter.jp