Skip to content

CDRIVER-1330 remove automatic init/cleanup #1938

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 20, 2025
Merged

Conversation

kevinAlbs
Copy link
Collaborator

@kevinAlbs kevinAlbs commented Mar 19, 2025

Removes deprecated behavior enabled by ENABLE_AUTOMATIC_INIT_AND_CLEANUP.

To help users identify a missing call to mongoc_init a check is added in the construction of mongoc_client_t and mongoc_client_pool_t to return an error if mongoc_init was not called. For example:

// mongoc_init() was not called previously!
mongoc_client_t *client = mongoc_client_new_from_uri_with_error (uri, &error);
if (!client) {
    fprintf (stderr, "error creating client: %s\n", error.message);
    return EXIT_FAILURE;
}

Before the check, an assert fails:

./cmake-build/src/libmongoc/example-client       
/Users/kevin.albertson/code/tasks/mongo-c-driver-2.0/src/libmongoc/src/mongoc/mongoc-handshake.c:709 _mongoc_handshake_freeze(): assertion failed: pthread_mutex_lock (&(&gHandshakeLock)->wrapped_mutex) == 0

With the check, this becomes:

error creating client: Attempting to create client, but libmongoc not initialized. Call mongoc_init

@kevinAlbs kevinAlbs marked this pull request as ready for review March 19, 2025 20:08
Copy link
Contributor

@vector-of-bool vector-of-bool left a comment

Choose a reason for hiding this comment

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

Yay!

@kevinAlbs kevinAlbs merged commit 1ca2bfa into mongodb:master Mar 20, 2025
40 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants