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

Connections should use server descriptions from handshake, not monitoring

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.19.0
    • Affects Version/s: None
    • Component/s: libmongoc, network
    • Labels:
      None

      When a stream is fetched for an operation, libmongoc fetches the server description from the topology description and uses that metadata for wire version checks, checking for supported compression.

      This is explicitly discouraged by SDAM's Warning about the maxWireVersion from a monitor's ismaster response and may make the driver susceptible to racy comparisons. For example:

      1. Thread 1 runs an insert. This creates a stream, performs a handshake, creates a
      cluster node, and proceeds to insert.
      2. Later, thread 1 begins another insert operation. It selects the primary, but just before it calls _mongoc_cluster_stream_for_server...
      3. Thread 2 runs an insert, gets a network error, and marks the server as Unknown.
      4. Thread 1 continues, and creates a server stream with an Unknown server description. Any wire version checks it does will check with wire version 0.

      We've seen bugs of this type before, example: CDRIVER-3404.

      It seems like there was at least some intention to fix this at some point. mongoc_cluster_node_t has its own copies of max_wire_version, min_wire_version, max_write_batch_size, max_bson_obj_size, and max_msg_size. But those fields are unused.

            Assignee:
            kevin.albertson@mongodb.com Kevin Albertson
            Reporter:
            kevin.albertson@mongodb.com Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: