Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-3969

Destruction of cursor leads to failed bson assert of the cursor server_id

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.24.2
    • Affects Version/s: 1.16.1, 1.17.5
    • Component/s: libmongoc
    • Environment:
      Windows 10 with mongoc driver 1.75.5
      Ubuntu 20.04.2 LTS with mongoc driver 1.16.1 (inside Windows Subsystem for Linux 2)

      I encountered an issue where the mongoc_cursor_destroy function is not able to destroy a cursor. I attached a file with a small c program that demonstrates the issue. You need to replace the uri_string, db_name & collection_name so they are valid for your system. The issue only occurs when the collection has more than 100 elements.

      The crucial part in the attached c program is the following:

      mongoc_client_command_with_opts(client, db_name, command, NULL, NULL, &reply, &error);
      cursor = mongoc_cursor_new_from_command_reply_with_opts(client, &reply, NULL);
      mongoc_cursor_destroy(cursor);
      

       

      The cursor returned from mongoc_cursor_new_from_command_reply_with_opts has a non zero cursor_id and a server_id which is zero.

      This leads to the failure of BSON_ASSERT(server_id) during the destruction of the cursor inside mongoc_cluster_stream_for_server() in mongoc-cluster.c.

      The log output is the following:

      /build/mongo-c-driver-RRvvb_/mongo-c-driver-1.16.1/src/libmongoc/src/mongoc/mongoc-cluster.c:1913 mongoc_cluster_stream_for_server(): precondition failed: server_id
      Aborted
      

            Assignee:
            kevin.albertson@mongodb.com Kevin Albertson
            Reporter:
            johannes.schulte@inmation.com Johannes Schulte
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: