Hi, currently the function Server::run_server_on_runtime consumes the tokio::runtime::Runtime. This works fine with block set to true, but when block is set to false, the runtime gets dropped after Some(runtime.spawn(server_task)).
|
pub fn run_server_on_runtime<F>( |
|
runtime: tokio::runtime::Runtime, |
|
server_task: F, |
|
block: bool, |
|
) -> Option<tokio::task::JoinHandle<<F as futures::Future>::Output>> |
|
where |
|
F: std::future::Future + Send + 'static, |
|
F::Output: Send + 'static, |
|
{ |
|
if block { |
|
runtime.block_on(server_task); |
|
info!("Server has finished"); |
|
None |
|
} else { |
|
Some(runtime.spawn(server_task)) |
|
} |
|
} |
This is a problem, because "Shutting down the runtime is done by dropping the value" (see
https://docs.rs/tokio/1.41.1/tokio/runtime/struct.Runtime.html#shutdown). I don't see a reason why the run_server_on_runtime method would need to consume the value, so passing in the runtime by reference would most likely work, but I think it would even be better to use a
tokio::runtime::Handle, since this can also be obtained via Handle::current() when the runtime is created by tokio through #[tokio::main] instead of explicitly by the user.
Hi, currently the function
Server::run_server_on_runtimeconsumes thetokio::runtime::Runtime. This works fine withblockset to true, but whenblockis set to false, the runtime gets dropped afterSome(runtime.spawn(server_task)).opcua/lib/src/server/server.rs
Lines 250 to 266 in fcc89d8
This is a problem, because "Shutting down the runtime is done by dropping the value" (see https://docs.rs/tokio/1.41.1/tokio/runtime/struct.Runtime.html#shutdown). I don't see a reason why the run_server_on_runtime method would need to consume the value, so passing in the runtime by reference would most likely work, but I think it would even be better to use a
tokio::runtime::Handle, since this can also be obtained via Handle::current() when the runtime is created by tokio through #[tokio::main] instead of explicitly by the user.