mongodb / mongo-rust-driver

The official MongoDB Rust Driver
https://www.mongodb.com/docs/drivers/rust/current/
Apache License 2.0
1.44k stars 163 forks source link

Failure to parse hello response from server #1024

Closed yourlogarithm closed 8 months ago

yourlogarithm commented 8 months ago

Versions/Environment

  1. What version of Rust are you using?

    • rustc 1.77.0-nightly (5d3d3479d 2024-01-23)
  2. What operating system are you using?

    • System: Arch Linux
    • Kernel: Linux 6.7.3-arch1-2
    • Architecture: x86-64
    • Hardware Vendor: Dell Inc.
    • Hardware Model: Latitude 5531
  3. What versions of the driver and its dependencies are you using?

  4. What version of MongoDB are you using? (Check with the MongoDB shell using db.version())

    • 4.4.12
  5. What is your MongoDB topology (standalone, replica set, sharded cluster, serverless)?

    • replica set

Describe the bug

connectionId expected to be i64 but is Double

To Reproduce

  1. Modify this function for a more verbose error:

    pub(crate) fn into_hello_reply(self) -> Result<HelloReply> {
    match self.body::<CommandResponse<HelloCommandResponse>>() {
      Ok(response) if response.is_success() => {
          let server_address = self.source_address().clone();
          let cluster_time = response.cluster_time().cloned();
          Ok(HelloReply {
              server_address,
              command_response: response.body,
              cluster_time,
              raw_command_response: self.into_raw_document_buf(),
          })
      },
      Ok(_) => {
          // Handle the case where the response is Ok but does not meet is_success condition
          Err(ErrorKind::InvalidResponse {
              message: String::from("The command response was not successful.")
          }.into())
      },
      Err(err0) => match self.body::<CommandResponse<CommandErrorBody>>() {
          Ok(command_error_body) => Err(Error::new(
              ErrorKind::Command(command_error_body.body.command_error),
              command_error_body.body.error_labels,
          )),
          Err(err1) => Err(ErrorKind::InvalidResponse {
              message: format!("invalid server response: {err0:?}\nbody: {:?}", self.raw.to_document())
          }
          .into()),
      },
    }
    }
  2. Use this connection function

    async fn get_db(var: &str, db_name: &str) -> Result<mongodb::Database, Box<dyn Error>> {
    let mut options = mongodb::options::ClientOptions::parse(env::var(var)?).await?;
    options.app_name = Some("meta-validator".to_string());
    // println!("{:?}", options);
    let client = mongodb::Client::with_options(options)?;
    let databases = client.list_database_names(None, None).await?;
    debug!("Connected to {}: {:?}", db_name, databases);
    Ok(client.database(db_name))
    }
  3. Get the error:

    Error { kind: InvalidResponse { message: \"invalid type: floating point `1162786981.0`, expected i64\" }, labels: {}, wire_version: None, source: None }
    body: Ok(Document({ ..., \"connectionId\": Double(1162786981.0), \"minWireVersion\": Int32(0), ... }))
abr-egn commented 8 months ago

Thank you for the detailed bug report! I'm looking into this now.

abr-egn commented 8 months ago

I've reproduced this locally; we'll have a fix out shortly and will cut a patch release to include it.

abr-egn commented 8 months ago

We just released version 2.8.1 of the driver which fixes this issue. Again, thanks for the report!