Using `r2d2_postgres` with lazy_static doesn’t work

I’m having trouble initializing a r2d2_postgres pool with lazy_static:

lazy_static! {
    static ref DB_POOL: Pool<PostgresConnectionManager<NoTls>> = {
        let manager = PostgresConnectionManager::new(config.parse().unwrap(), NoTls);
        Pool::new(manager).unwrap()
    };
}

I was using r2d2_sqlite before and everything was working fine. Here’s the trace:

thread 'main' panicked at ~/.cargo/registry/src/index.crates.io6f17d22bba15001f/postgres-0.19.9/src/connection.rs:66:22:

Cannot start a runtime from within a runtime. This happens because a function (like`block_on`) attempted to block the current thread while the thread is being used to drive asynchronous tasks.

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace thread 'main' panicked at ~/.cargo/registry/src/index.crates.io-6f17d 22bba15001f/postgres-0.19.9/src/connection.rs:66:22:

Cannot start a runtime from within a runtime. This happens because a function (like `block_on`) attempted to block the current thread while the thread is being used to drive asynchronous tasks.

stack backtrace:
   0:     0x55a3885c4dea - std::backtrace_rs::backtrace::libunwind::trace::hb5961a2c6b56061b
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x55a3885c4dea - std::backtrace_rs::backtrace::trace_unsynchronized::h441585ce65458a75
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x55a3885c4dea - std::sys::backtrace::_print_fmt::h175f8265af37e6cb
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/sys/backtrace.rs:66:9
   3:     0x55a3885c4dea - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::haf9d4ce087fe74a0
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/sys/backtrace.rs:39:26
   4:     0x55a3885eea53 - core::fmt::rt::Argument::fmt::h641ec953a6c58d0a
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/core/src/fmt/rt.rs:177:76
   5:     0x55a3885eea53 - core::fmt::write::h6d8d6eef4a4af1ac
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/core/src/fmt/mod.rs:1186:21
   6:     0x55a3885c0ca3 - std::io::Write::write_fmt::h9c1a7b2c301e0052
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/io/mod.rs:1833:15
   7:     0x55a3885c4c32 - std::sys::backtrace::BacktraceLock::print::h5a5be8b1e95a2bbb
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/sys/backtrace.rs:42:9
   8:     0x55a3885c6037 - std::panicking::default_hook::{{closure}}::ha72f3fa07467f26a
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/panicking.rs:268:22
   9:     0x55a3885c5e66 - std::panicking::default_hook::hcc7760cf4378effc
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/panicking.rs:295:9
  10:     0x55a3885c6667 - std::panicking::rust_panic_with_hook::hfa739d875be2cf67
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/panicking.rs:801:13
  11:     0x55a3885c64c6 - std::panicking::begin_panic_handler::{{closure}}::h9a9134f6e05b41bd
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/panicking.rs:667:13
  12:     0x55a3885c52c9 - std::sys::backtrace::__rust_end_short_backtrace::h35fa4dfdd9fe9e0c
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/sys/backtrace.rs:170:18
  13:     0x55a3885c618c - rust_begin_unwind
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/panicking.rs:665:5
  14:     0x55a3885eba20 - core::panicking::panic_fmt::hc3e7c6c5c469a97f
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/core/src/panicking.rs:74:14
  15:     0x55a387dd84c6 - tokio::runtime::context::runtime::enter_runtime::h241c00a460a1fbd3
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/context/runtime.rs:68:5
  16:     0x55a387dcbec4 - tokio::runtime::scheduler::current_thread::CurrentThread::block_on::h02f19359830f6e75
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/scheduler/current_thread/mod.rs:184:9
  17:     0x55a387dcb451 - tokio::runtime::runtime::Runtime::block_on_inner::h9e97f1781ae858b6
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/runtime.rs:368:47
  18:     0x55a387dcb84e - tokio::runtime::runtime::Runtime::block_on::h0d7dfbc8f7c98a37
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/runtime.rs:342:13
  19:     0x55a387dca076 - postgres::connection::Connection::poll_block_on::h5821a8625aaf933d
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/postgres-0.19.9/src/connection.rs:66:9
  20:     0x55a387de0ba6 - postgres::client::Client::close_inner::h0f9614003b00a144
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/postgres-0.19.9/src/client.rs:616:9
  21:     0x55a387de0a2e - <postgres::client::Client as core::ops::drop::Drop>::drop::he73f036533ce03e9
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/postgres-0.19.9/src/client.rs:20:17
  22:     0x55a387dc95f7 - core::ptr::drop_in_place<postgres::client::Client>::hcd1026e4c7ab4e6e
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/core/src/ptr/mod.rs:574:1
  23:     0x55a3877360f7 - core::ptr::drop_in_place<r2d2::Conn<postgres::client::Client>>::h7a97120ab11c206a
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/core/src/ptr/mod.rs:574:1
  24:     0x55a3877d9d6a - r2d2::Pool<M>::try_get_inner::h2e39ae956ee0a512
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/r2d2-0.8.10/src/lib.rs:483:13
  25:     0x55a3877d929e - r2d2::Pool<M>::get_timeout::hceeb88dd5f4d411f
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/r2d2-0.8.10/src/lib.rs:424:19
  26:     0x55a3877da091 - r2d2::Pool<M>::get::hea1b50a653f8c20b
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/r2d2-0.8.10/src/lib.rs:411:9
  27:     0x55a3875f1348 - joogle::db::sites::init_table::h717a8c0acd2e64eb
                               at /home/johanmontorfano/Documents/Projects/joogle/src/db/sites.rs:9:20
  28:     0x55a3877a51c1 - joogle::main::{{closure}}::h57b83d07a13c3021
                               at /home/johanmontorfano/Documents/Projects/joogle/src/main.rs:84:5
  29:     0x55a3877d36cd - <core::pin::Pin<P> as core::future::future::Future>::poll::h175dfb280ef2cdf7
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/core/src/future/future.rs:123:9
  30:     0x55a3877893df - tokio::runtime::park::CachedParkThread::block_on::{{closure}}::h66545313ddef3df1
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/park.rs:281:63
  31:     0x55a387786326 - tokio::runtime::coop::with_budget::h6efd943802836fc8
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/coop.rs:107:5
  32:     0x55a387786326 - tokio::runtime::coop::budget::hf96bceea67332ee3
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/coop.rs:73:5
  33:     0x55a387786326 - tokio::runtime::park::CachedParkThread::block_on::ha202f72947e1d848
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/park.rs:281:31
  34:     0x55a387800720 - tokio::runtime::context::blocking::BlockingRegionGuard::block_on::h0613e378a4cd988e
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/context/blocking.rs:66:9
  35:     0x55a38765032e - tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}}::h04a9fc77b29210c2
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/scheduler/multi_thread/mod.rs:87:13
  36:     0x55a3876956e0 - tokio::runtime::context::runtime::enter_runtime::h6d4263a341803676
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/context/runtime.rs:65:16
  37:     0x55a38764fea1 - tokio::runtime::scheduler::multi_thread::MultiThread::block_on::h03c08d760b2dd6cb
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/scheduler/multi_thread/mod.rs:86:9
  38:     0x55a38766fe12 - tokio::runtime::runtime::Runtime::block_on_inner::h05d2c20946a5ced0
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/runtime.rs:370:45
  39:     0x55a38767144d - tokio::runtime::runtime::Runtime::block_on::h0dfd39080eed2e28
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/runtime.rs:340:13
  40:     0x55a387759b40 - rocket::async_run::h6e04995ce127c884
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rocket-0.5.1/src/lib.rs:250:18
  41:     0x55a3877598c9 - rocket::async_main::h5d0f258c8f30266d
                               at /home/johanmontorfano/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rocket-0.5.1/src/lib.rs:282:5
  42:     0x55a38766eb32 - joogle::main::h8ef69abf974f528d
                               at /home/johanmontorfano/Documents/Projects/joogle/src/main.rs:80:23
  43:     0x55a3877299ab - core::ops::function::FnOnce::call_once::h4e8011241f5ad359
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/core/src/ops/function.rs:250:5
  44:     0x55a3877d296e - std::sys::backtrace::__rust_begin_short_backtrace::h4e59c8bf79320b4b
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/sys/backtrace.rs:154:18
  45:     0x55a387690e41 - std::rt::lang_start::{{closure}}::h0666c996fa6c7454
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/rt.rs:164:18
  46:     0x55a3885b9f40 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h5b8616fa64754f67
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/core/src/ops/function.rs:284:13
  47:     0x55a3885b9f40 - std::panicking::try::do_call::hb9ece8d760e9492d
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/panicking.rs:557:40
  48:     0x55a3885b9f40 - std::panicking::try::hec186f0da2e0e0f2
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/panicking.rs:520:19
  49:     0x55a3885b9f40 - std::panic::catch_unwind::h21bd59bf1b1faa4d
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/panic.rs:348:14
  50:     0x55a3885b9f40 - std::rt::lang_start_internal::{{closure}}::hc035020e9c22a2ad
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/rt.rs:143:48
  51:     0x55a3885b9f40 - std::panicking::try::do_call::ha826433f6400f059
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/panicking.rs:557:40
  52:     0x55a3885b9f40 - std::panicking::try::h6ba5225898f870bf
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/panicking.rs:520:19
  53:     0x55a3885b9f40 - std::panic::catch_unwind::hb2c7060d484d84a5
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/panic.rs:348:14
  54:     0x55a3885b9f40 - std::rt::lang_start_internal::hc44f35ca2c603ce0
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/rt.rs:143:20
  55:     0x55a387690e1a - std::rt::lang_start::h3749fb1487ab32bd
                               at /rustc/7042c269c166191cd5d8daf0409890903df7af57/library/std/src/rt.rs:163:17
  56:     0x55a38766eb5e - main
  57:     0x7fb608729248 - __libc_start_call_main
  58:     0x7fb60872930b - __libc_start_main_impl
  59:     0x55a3875ef3b5 - _start
  60:                0x0 - <unknown>
thread 'main' panicked at core/src/panicking.rs:229:5:
panic in a destructor during cleanup
thread caused non-unwinding panic. aborting.
[1]    12383 IOT instruction (core dumped)  cargo run

I tried using OneCell and other techniques I found on the web, but nothing solves this issue.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật