Rust MongoDB驱动程序2.0.0错误:意外文件结束

siv3szwd  于 2023-06-29  发布在  Go
关注(0)|答案(2)|浏览(105)

我尝试使用rust来构建一个新的服务,使用现有的MongoDB URI:
mongodb://username:pwd@ip:27017/db_name?authSource=admin
在机器上:CentOS7 x86,此MongoDB可用,命令为:

[root@VM_centos ~]# mongo mongodb://username:pwd@ip:27017/db_name?authSource=admin
MongoDB shell version: 3.2.18
connecting to: ......
mongos>

也可以使用NodeJS驱动程序,但不适用于Rust MongoDB驱动程序(MongoDB驱动程序2.0.0)。
Rust代码:

let uri = "mongodb://username:pwd@ip:27017/db_name?authSource=admin";
 let client_options = ClientOptions::parse(uri).await?;
 let client = Client::with_options(client_options)?;
 client
        .database("admin")
        .run_command(doc! {"ping": 1}, None)
        .await?;

Rust代码出现错误:

Error: Server selection timeout: No available servers. Topology: { Type: Unknown, Servers: [ { Address: ***:27017, Type: Unknown, Error: unexpected end of file }, ] }

我打印完整的轨道:

Error: Server selection timeout: No available servers. Topology: { Type: Unknown, Servers: [ { Address: ***:27017, Type: Unknown, Error: unexpected end of file }, ] }
thread 'controller::game_service::test_super::test_game_update_one' panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `0`: the test returned a termination value with a non-zero status code (1) which indicates a failure', /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/test/src/lib.rs:194:5
stack backtrace:
   0:     0x5652bdaafbd0 - std::backtrace_rs::backtrace::libunwind::trace::ha0ad43e8a952bfe7
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x5652bdaafbd0 - std::backtrace_rs::backtrace::trace_unsynchronized::h6830419c0c4130dc
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x5652bdaafbd0 - std::sys_common::backtrace::_print_fmt::h8f3516631ffa1ef5
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x5652bdaafbd0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he1640d5f0d93f618
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x5652bdad598c - core::fmt::write::h88012e1f01caeebf
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/fmt/mod.rs:1115:17
   5:     0x5652bdaa8b25 - std::io::Write::write_fmt::h7728c39ea5632753
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/io/mod.rs:1665:15
   6:     0x5652bdab1f1b - std::sys_common::backtrace::_print::ha1f00492f406a015
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x5652bdab1f1b - std::sys_common::backtrace::print::hd54561b13feb6af3
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x5652bdab1f1b - std::panicking::default_hook::{{closure}}::h84fe124cd0864662
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:208:50
   9:     0x5652bdab1a2c - std::panicking::default_hook::h5a8e74a76ce290a7
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:222:9
  10:     0x5652bdab25e4 - std::panicking::rust_panic_with_hook::h67c812a4fe9d4c91
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:622:17
  11:     0x5652bdab20c7 - std::panicking::begin_panic_handler::{{closure}}::h33f9c1b96af300d7
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:519:13
  12:     0x5652bdab00cc - std::sys_common::backtrace::__rust_end_short_backtrace::h51bae64be5921f0e
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/sys_common/backtrace.rs:141:18
  13:     0x5652bdab2029 - rust_begin_unwind
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:515:5
  14:     0x5652bc52cdc1 - core::panicking::panic_fmt::h12a3a3c256485fca
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:92:14
  15:     0x5652bdad406e - core::panicking::assert_failed_inner::hd10540743cd0e11a
  16:     0x5652bda80b1a - core::panicking::assert_failed::h5c3efd64b01ea4b7
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:117:5
  17:     0x5652bc7facc1 - test::assert_test_result::h1eea97f876779783
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/test/src/lib.rs:194:5
  18:     0x5652bc564a9d - manager::controller::game_service::test_super::test_game_update_one::{{closure}}::hafab44beff96efa3
                               at /home/gitlab-runner/builds/141526a3/0/zoo/server_mgr_rs/src/controller/game_service.rs:378:11
  19:     0x5652bc884a4e - core::ops::function::FnOnce::call_once::h37b4a4df41b75102
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/ops/function.rs:227:5
  20:     0x5652bcbbfe13 - core::ops::function::FnOnce::call_once::h5aba9a5d361d6c79
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/ops/function.rs:227:5
  21:     0x5652bcbbfe13 - test::__rust_begin_short_backtrace::h705bb53b2b1d45e6
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/test/src/lib.rs:578:5
  22:     0x5652bcbbe8c8 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha20f614d7c0b2b6d
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/alloc/src/boxed.rs:1572:9
  23:     0x5652bcbbe8c8 - <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::hf02f19eeb64ceabd
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panic.rs:347:9
  24:     0x5652bcbbe8c8 - std::panicking::try::do_call::h4bfab65eb3b4b036
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:401:40
  25:     0x5652bcbbe8c8 - std::panicking::try::h6613a46a6d2b6f88
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:365:19
  26:     0x5652bcbbe8c8 - std::panic::catch_unwind::h9f07b17b60991273
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panic.rs:434:14
  27:     0x5652bcbbe8c8 - test::run_test_in_process::hc38797eecf07854f
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/test/src/lib.rs:601:18
  28:     0x5652bcbbe8c8 - test::run_test::run_test_inner::{{closure}}::hac209db8bce0fd77
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/test/src/lib.rs:493:39
  29:     0x5652bcb8d05d - test::run_test::run_test_inner::{{closure}}::h4aefdd4b4a423e20
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/test/src/lib.rs:520:37
  30:     0x5652bcb8d05d - std::sys_common::backtrace::__rust_begin_short_backtrace::h652c9e2663704700
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/sys_common/backtrace.rs:125:18
  31:     0x5652bcb91838 - std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}}::hd84fd5e0b5b1f45f
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/thread/mod.rs:476:17
  32:     0x5652bcb91838 - <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::he23556962a2ae14b
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panic.rs:347:9
  33:     0x5652bcb91838 - std::panicking::try::do_call::h67d4f93e1fbaa5f9
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:401:40
  34:     0x5652bcb91838 - std::panicking::try::h396886e678db815e
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:365:19
  35:     0x5652bcb91838 - std::panic::catch_unwind::hc1d64dcecf0a00e0
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panic.rs:434:14
  36:     0x5652bcb91838 - std::thread::Builder::spawn_unchecked::{{closure}}::hc2644cf33cb61d8e
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/thread/mod.rs:475:30
  37:     0x5652bcb91838 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h4473c2c77b66963f
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/ops/function.rs:227:5
  38:     0x5652bdab84d7 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6bff7798948b1075
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/alloc/src/boxed.rs:1572:9
  39:     0x5652bdab84d7 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc2d25ac38f6b2342
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/alloc/src/boxed.rs:1572:9
  40:     0x5652bdab84d7 - std::sys::unix::thread::Thread::new::thread_start::hbba5bc368baac205
                               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/sys/unix/thread.rs:74:17
  41:     0x7f572bb92e65 - start_thread
  42:     0x7f572b3b588d - clone
  43:                0x0 - <unknown>

和ClientOptions信息:
ClientOptions { hosts:[TCP { host:“hiden”,端口:Some(27017)}],app_name:Some(“game_conf”),compressors:无,连接超时:无,凭据:Some(Credential(“REDACTED”)),direct_connection:无,driver_info:无,heartbeat_freq:无,local_threshold:无,max_idle_time:无,max_pool_size:无,最小池大小:Some(5),read_concern:无,repl_set_name:无,retry_reads:无,retry_writes:无,selection_criteria:无,server_API:无,server_selection_timeout:无,socket_timeout:None,tls:Some(Disabled),write_concern:无,zlib_compression:无,original_srv_info:无,original_uri:一些(“mongodb://hiden:hiden@hiden:27017/gamesLog?authSource=admin&tls=false”),resolver_config:无,allow_load_balanced:false,load_balanced:无}
这花了我2天的时间,但没有找到解决方案:(
我也尝试使用TLS/SSL,但是
错误:DNS解析期间发生错误:InvalidDNSNameError

qyswt5oh

qyswt5oh1#

这可能是兼容性问题。您的MongoDB版本是3.2.x。但是,在驱动程序的兼容性表中。它只支持MongoDB 3.6。也许你可以尝试使用支持的MongoDB版本,看看这个问题是否已经解决。
--by @Joe_Jingyu

5hcedyr0

5hcedyr02#

有类似的问题。在我的情况下,帮助添加我的IP到Mongo
网络访问> IP访问列表

相关问题