suharev7 / clickhouse-rs

Asynchronous ClickHouse client library for Rust programming language.
MIT License
324 stars 121 forks source link

Using Clickhouse-rs in async context throws exceptions on shutdown #161

Closed mikolajsnioch closed 3 years ago

mikolajsnioch commented 3 years ago

I am using clickhouse-rs in a gui application. It works as expected until I try to close the program. When I do, I get an exception for each ClientHandle that was created:

Cannot drop a runtime in a context where blocking is not allowed. This happens when a runtime is dropped from within an asynchronous context.

I reviewed the stack trace and with some web search found that this issue has happened before with other crates. First the relevant part of the stack trace (full stack trace at the bottom):

 13:     0x562f0dc6cc89 - std::panicking::begin_panic::ha46902d46371d310
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:541:12
  14:     0x562f0dc0e43f - tokio::runtime::blocking::shutdown::Receiver::wait::h936f598116b25343
                               at /home/mks/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.12.0/src/runtime/blocking/shutdown.rs:51:21
  15:     0x562f0dbea27a - tokio::runtime::blocking::pool::BlockingPool::shutdown::h8ff67935fe502e92
                               at /home/mks/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.12.0/src/runtime/blocking/pool.rs:145:12

This Rocket issue has a stack trace with identical part as quoted and it seems to me it is the same problem as the one I am experiencing: https://github.com/SergioBenitez/Rocket/issues/1466 . This comment in particular should be helpful: https://github.com/SergioBenitez/Rocket/issues/1466#issuecomment-722008413

My Cargo.toml has this: clickhouse-rs = { git = "https://github.com/suharev7/clickhouse-rs" }

Full Stack Trace:

stack backtrace:
   0:     0x562f0dca4010 - std::backtrace_rs::backtrace::libunwind::trace::h34055254b57d8e79
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x562f0dca4010 - std::backtrace_rs::backtrace::trace_unsynchronized::h8f1e3fbd9afff6ec
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x562f0dca4010 - std::sys_common::backtrace::_print_fmt::h3a99a796b770c360
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x562f0dca4010 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h32d1f94a80615d18
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x562f0dcc711c - core::fmt::write::h306731c068f7162c
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/fmt/mod.rs:1110:17
   5:     0x562f0dc9e765 - std::io::Write::write_fmt::hd2fa90334eee2a21
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/io/mod.rs:1588:15
   6:     0x562f0dca625b - std::sys_common::backtrace::_print::h5abaa2601a852287
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x562f0dca625b - std::sys_common::backtrace::print::h8d81445442bb638f
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x562f0dca625b - std::panicking::default_hook::{{closure}}::hcfe804496a9fa747
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:208:50
   9:     0x562f0dca5d31 - std::panicking::default_hook::hbea8e3ccf2ba8901
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:225:9
  10:     0x562f0dca6924 - std::panicking::rust_panic_with_hook::h7ee9e1a2d0f8975a
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:622:17
  11:     0x562f0dc6cd53 - std::panicking::begin_panic::{{closure}}::hd4eb21342d44c021
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:542:9
  12:     0x562f0dc6ad79 - std::sys_common::backtrace::__rust_end_short_backtrace::h9eaf511fbe9e3435
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/sys_common/backtrace.rs:141:18
  13:     0x562f0dc6cc89 - std::panicking::begin_panic::ha46902d46371d310
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:541:12
  14:     0x562f0dc0e43f - tokio::runtime::blocking::shutdown::Receiver::wait::h936f598116b25343
                               at /home/mks/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.12.0/src/runtime/blocking/shutdown.rs:51:21
  15:     0x562f0dbea27a - tokio::runtime::blocking::pool::BlockingPool::shutdown::h8ff67935fe502e92
                               at /home/mks/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.12.0/src/runtime/blocking/pool.rs:145:12
  16:     0x562f0dbea7bc - <tokio::runtime::blocking::pool::BlockingPool as core::ops::drop::Drop>::drop::h8874b5990f5d8c8b
                               at /home/mks/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.12.0/src/runtime/blocking/pool.rs:162:9
  17:     0x562f0dbf6717 - core::ptr::drop_in_place<tokio::runtime::blocking::pool::BlockingPool>::he6b7d104b7012f54
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/ptr/mod.rs:192:1
  18:     0x562f0dbf51da - core::ptr::drop_in_place<tokio::runtime::Runtime>::h194b4ea87d98392f
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/ptr/mod.rs:192:1
  19:     0x562f0d1898fb - core::ptr::drop_in_place<iced::executor::platform::Default>::h1dc7da28f895166c
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/ptr/mod.rs:192:1
  20:     0x562f0d187273 - core::ptr::drop_in_place<iced_futures::runtime::Runtime<iced_native::hasher::Hasher,(iced_native::event::Event,iced_native::event::Status),iced::executor::platform::Default,iced_winit::proxy::Proxy<shamancharts::gui::Message>,shamancharts::gui::Message>>::h037f2145db12255d
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/ptr/mod.rs:192:1
  21:     0x562f0d057bb4 - iced_glutin::application::run_instance::{{closure}}::h7b41be065ecd89cf
                               at /home/mks/.cargo/registry/src/github.com-1ecc6299db9ec823/iced_glutin-0.2.0/src/application.rs:152:1
  22:     0x562f0d1dc81b - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h87e6c07b9d709973
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/future/mod.rs:80:19
  23:     0x562f0d059525 - iced_glutin::application::run::{{closure}}::hafad2ead72816c1c
                               at /home/mks/.cargo/registry/src/github.com-1ecc6299db9ec823/iced_glutin-0.2.0/src/application.rs:129:24
  24:     0x562f0d07ea47 - winit::platform_impl::platform::sticky_exit_callback::h711cb15aaf3950ea
                               at /home/mks/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.24.0/src/platform_impl/linux/mod.rs:736:5
  25:     0x562f0d148e75 - winit::platform_impl::platform::wayland::event_loop::EventLoop<T>::run_return::h1562a4a17cf9624b
                               at /home/mks/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.24.0/src/platform_impl/linux/wayland/event_loop/mod.rs:323:21
  26:     0x562f0d14cb74 - winit::platform_impl::platform::wayland::event_loop::EventLoop<T>::run::h32d16db522d92f9c
                               at /home/mks/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.24.0/src/platform_impl/linux/wayland/event_loop/mod.rs:191:9
  27:     0x562f0d07e879 - winit::platform_impl::platform::EventLoop<T>::run::hbf8112fd6f899dc0
                               at /home/mks/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.24.0/src/platform_impl/linux/mod.rs:652:56
  28:     0x562f0d120c66 - winit::event_loop::EventLoop<T>::run::hc37b6b5378b56152
                               at /home/mks/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.24.0/src/event_loop.rs:154:9
  29:     0x562f0d0590cb - iced_glutin::application::run::h037a82d448df2ce1
                               at /home/mks/.cargo/registry/src/github.com-1ecc6299db9ec823/iced_glutin-0.2.0/src/application.rs:104:5
  30:     0x562f0d0b32f6 - iced::application::Application::run::hfca1acc51af9aa6c
                               at /home/mks/.cargo/registry/src/github.com-1ecc6299db9ec823/iced-0.3.0/src/application.rs:219:16
  31:     0x562f0d103561 - shamancharts::main::{{closure}}::h7c39bf1d3ab03c6b
mikolajsnioch commented 3 years ago

I think I am wrong about this and this is an issue with how I am using it.