Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Node thread creation (use tokio::sync::oneshot) #982

Closed
ipetr0v opened this issue May 13, 2020 · 0 comments · Fixed by #985
Closed

Refactor Node thread creation (use tokio::sync::oneshot) #982

ipetr0v opened this issue May 13, 2020 · 0 comments · Fixed by #985
Assignees

Comments

@ipetr0v
Copy link
Contributor

ipetr0v commented May 13, 2020

Currently two pseudo-Nodes (gRPC server and client) are using Tokio Runtime in order to run async routines:

let mut async_runtime = tokio::runtime::Builder::new()
// Use simple scheduler that runs all tasks on the current-thread.
// https://docs.rs/tokio/0.2.16/tokio/runtime/index.html#basic-scheduler
.basic_scheduler()
// Enables the I/O driver.
// Necessary for using net, process, signal, and I/O types on the Tokio runtime.
.enable_io()
.build()
.expect("Couldn't create an Async runtime");

let result = async_runtime.block_on(server);

And because these threads are blocked, they cannot join correctly when the Runtime is trying to stop the Node.

We might need to use tokio::sync::oneshot, that is already used by the AuxServer:

notify_receiver: tokio::sync::oneshot::Receiver<()>,
) {
let mut tokio_runtime = tokio::runtime::Runtime::new().expect("Couldn't create Tokio runtime");
tokio_runtime.block_on(futures::future::select(
Box::pin(make_server(port, runtime)),
notify_receiver,
));

let (notify_sender, notify_receiver) = tokio::sync::oneshot::channel::<()>();
info!("spawning {} server on new thread", name);
let join_handle = thread::Builder::new()
.name(format!("{}-server", name))
.spawn(move || f(port, runtime, notify_receiver))
.expect("failed to spawn introspection thread");

fn drop(&mut self) {
let join_handle = self.join_handle.take();
let notify_sender = self.notify_sender.take();
if let Some(notify_sender) = notify_sender {
info!("stopping {} server", self.name);
notify_sender.send(()).unwrap();
}
if let Some(join_handle) = join_handle {
let result = join_handle.join();
info!("stopped {} server, result {:?}", self.name, result);
}
}

@ipetr0v ipetr0v self-assigned this May 13, 2020
ipetr0v added a commit that referenced this issue May 14, 2020
This change:
- Adds futures select for Tokio Runtime
- Temporary disables gRPC client tests in `abitest` since they now require TLS certificates (will be re-enabled after examples start using Rust Loader)

Fixes #982
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant