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

cannot connect to mongo atlas from aws instance #462

Closed yurenji closed 3 years ago

yurenji commented 3 years ago

I am following this doc to connect to a mongo atlas db from an AWS instance.

dependencies

[dependencies]
tokio = { version = "1.11.0", features = ["full"] }
mongodb = { version = "2.0.0", features = ["aws-auth"] }

code

let mut client_options = ClientOptions::parse("mongodb+srv://<username>:<password>@<cluster-url>/test?w=majority")
.await?;

error:

Error: Error { kind: ServerSelection { message: "Server selection timeout: No available servers. Topology: { Type: ReplicaSetNoPrimary, Servers: [ { Address: xxx.vzycd.mongodb.net:27017, Type: Unknown, Error: unexpected end of file }, { Address: xxx.vzycd.mongodb.net:27017, Type: Unknown, Error: unexpected end of file }, { Address: xxx.vzycd.mongodb.net:27017, Type: Unknown, Error: unexpected end of file }, ] }" }, labels: {} }

I tried both the SRV and non-SRV URI, neither of them work. However, I was able to use the URI to connect via python or golang code.

Can someone give me a hint about the root cause and solution?

patrickfreed commented 3 years ago

It’s possible you’re running into RUST-272 if your instance size is > M2 and running MongoDB < 4.2. This issue is due to the fact that MongoDB < 4.2 running on Atlas servers currently uses a different set of TLS ciphers than rustls (the TLS library the driver uses under the hood) supports. This can be worked around by upgrading your MongoDB version to 4.2 (which supports the newer ciphers) or by downgrading your instance size, if those are options available to you. Sorry for any inconvenience this may cause!

As a side note: you don't need the aws-auth feature flag unless you're using MONGODB-AWS authentication.

yurenji commented 3 years ago

@patrickfreed thanks! it's resolved after I updated the mongodb to 4.2