Uploaded image for project: 'Libmongocrypt'
  1. Libmongocrypt
  2. MONGOCRYPT-526

csfle lib_create() failed: Cannot initialize the Mongo Crypt Shared Support Library when it is already initialized

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 1.7.5
    • Affects Version/s: None
    • Component/s: None
    • None
    • Not Needed

      Both rust and python are seeing occasional csfle lib_create() failed: Cannot initialize the Mongo Crypt Shared Support Library when it is already initialized. [Error 3, code 1] errors when testing crypt_shared: PYTHON-3559 and RUST-1578. I have not been able to reproduce the error locally yet.

      abraham.egnor@mongodb.com was able to remove this error by putting a global mutex around mongocrypt_init and mongocrypt_destroy (here https://github.com/mongodb/libmongocrypt-rust/pull/20/files) which indicates this is a race condition in libmongocrypt itself.

      Here's an example:

       [2022/12/20 22:35:48.583] ERROR: test_legacy_badQueries_$pullAll_succeeds_on_unencrypted,_error_on_encrypted (test.test_encryption.TestSpec)
       [2022/12/20 22:35:48.583] ----------------------------------------------------------------------
       [2022/12/20 22:35:48.583] Traceback (most recent call last):
       [2022/12/20 22:35:48.583]   File "C:\data\mci\7d56f8d50d34074aa87d3e48f70ad8bc\src\test\__init__.py", line 603, in wrap
       [2022/12/20 22:35:48.583]     return f(*args, **kwargs)
       [2022/12/20 22:35:48.583]   File "C:\data\mci\7d56f8d50d34074aa87d3e48f70ad8bc\src\test\__init__.py", line 603, in wrap
       [2022/12/20 22:35:48.583]     return f(*args, **kwargs)
       [2022/12/20 22:35:48.583]   File "C:\data\mci\7d56f8d50d34074aa87d3e48f70ad8bc\src\test\test_encryption.py", line 686, in run_scenario
       [2022/12/20 22:35:48.583]     self.run_scenario(scenario_def, test)
       [2022/12/20 22:35:48.583]   File "C:\data\mci\7d56f8d50d34074aa87d3e48f70ad8bc\src\test\utils_spec_runner.py", line 520, in run_scenario
       [2022/12/20 22:35:48.583]     client = rs_client(
       [2022/12/20 22:35:48.583]   File "C:\data\mci\7d56f8d50d34074aa87d3e48f70ad8bc\src\test\utils.py", line 595, in rs_client
       [2022/12/20 22:35:48.583]     return _mongo_client(h, p, **kwargs)
       [2022/12/20 22:35:48.583]   File "C:\data\mci\7d56f8d50d34074aa87d3e48f70ad8bc\src\test\utils.py", line 575, in _mongo_client
       [2022/12/20 22:35:48.583]     return MongoClient(uri, port, **client_options)
       [2022/12/20 22:35:48.583]   File "C:\data\mci\7d56f8d50d34074aa87d3e48f70ad8bc\src\pymongo\mongo_client.py", line 831, in __init__
       [2022/12/20 22:35:48.583]     self._encrypter = _Encrypter(self, self.__options.auto_encryption_opts)
       [2022/12/20 22:35:48.583]   File "C:\data\mci\7d56f8d50d34074aa87d3e48f70ad8bc\src\pymongo\encryption.py", line 337, in __init__
       [2022/12/20 22:35:48.583]     self._auto_encrypter = AutoEncrypter(
       [2022/12/20 22:35:48.583]   File "Z:\data\mci\7d56f8d50d34074aa87d3e48f70ad8bc\src\venv-encryption\lib\site-packages\pymongocrypt\auto_encrypter.py", line 31, in __init__
       [2022/12/20 22:35:48.583]     self.mongocrypt = MongoCrypt(mongo_crypt_opts, callback)
       [2022/12/20 22:35:48.583]   File "Z:\data\mci\7d56f8d50d34074aa87d3e48f70ad8bc\src\venv-encryption\lib\site-packages\pymongocrypt\mongocrypt.py", line 194, in __init__
       [2022/12/20 22:35:48.583]     self.__init()
       [2022/12/20 22:35:48.583]   File "Z:\data\mci\7d56f8d50d34074aa87d3e48f70ad8bc\src\venv-encryption\lib\site-packages\pymongocrypt\mongocrypt.py", line 263, in __init
       [2022/12/20 22:35:48.583]     self.__raise_from_status()
       [2022/12/20 22:35:48.583]   File "Z:\data\mci\7d56f8d50d34074aa87d3e48f70ad8bc\src\venv-encryption\lib\site-packages\pymongocrypt\mongocrypt.py", line 279, in __raise_from_status
       [2022/12/20 22:35:48.583]     raise exc
       [2022/12/20 22:35:48.583] pymongocrypt.errors.MongoCryptError: csfle lib_create() failed: Cannot initialize the Mongo Crypt Shared Support Library when it is already initialized. [Error 3, code 1]
       [2022/12/20 22:35:48.583] ----------------------------------------------------------------------
      

      https://evergreen.mongodb.com/task/mongo_python_driver_tests_windows_encryption__platform~windows_64_vsMulti_small_auth_ssl~noauth_nossl_python_version_windows~3.10_encryption~encryption_crypt_shared_test_6.0_sharded_cluster_f5d09e1c97ca12c94c555b40364b2ae10ec5126c_22_12_20_19_39_04

            Assignee:
            kyle.kloberdanz@mongodb.com Kyle Kloberdanz (Inactive)
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: