[CONC-568] Race condition in loading of client plugins Created: 2021-10-05  Updated: 2021-10-08  Resolved: 2021-10-08

Status: Closed
Project: MariaDB Connector/C
Component/s: None
Affects Version/s: 3.2.3
Fix Version/s: 3.3.0, 3.2.5, 3.1.15

Type: Bug Priority: Major
Reporter: markus makela Assignee: Georg Richter
Resolution: Fixed Votes: 0
Labels: None


 Description   

When multiple threads in the same application attempt to connect to a server using a client-side authentication plugin, the following error can be observed from time to time.

1045: Plugin client_ed25519 could not be loaded: it is already loaded

Looking at the code in ma_client_plugin.c.in:

  /* make sure the plugin wasn't loaded meanwhile */
  if (find_plugin(plugin->name, plugin->type))
  {
    my_set_error(mysql, CR_AUTH_PLUGIN_CANNOT_LOAD,
                 SQLSTATE_UNKNOWN, ER(CR_AUTH_PLUGIN_CANNOT_LOAD),
                 plugin->name, "it is already loaded");
    plugin= NULL;
  }

we see that something that can only occur with more than one thread is treated as an error. Additionally, it seems that the initial find_plugin() call is not done under the same lock under which the plugin loading is done. This would explain why more than one thread attempts to load the same plugin.

I believe that either the whole mysql_client_find_plugin should be covered by the same mutex or the already existing plugin should be returned instead of treating it as an error.



 Comments   
Comment by Georg Richter [ 2021-10-08 ]

Please note that the commit message is partially incorrect. It doesn't affect mysql_load_plugins_v() api function, but mysql_client_register_plugin() api function

Generated at Thu Feb 08 03:06:14 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.