fix tokio
This commit is contained in:
@@ -13,7 +13,7 @@ path = "src/main.rs"
|
||||
[features]
|
||||
default = [ "rt-tokio" ]
|
||||
rt-async-std = [ "veilid-core/rt-async-std", "async-std", "opentelemetry/rt-async-std", "opentelemetry-otlp/grpc-sys"]
|
||||
rt-tokio = [ "veilid-core/rt-tokio", "tokio", "opentelemetry/rt-tokio"]
|
||||
rt-tokio = [ "veilid-core/rt-tokio", "tokio", "tokio-stream", "tokio-util", "opentelemetry/rt-tokio"]
|
||||
tracking = ["veilid-core/tracking"]
|
||||
|
||||
[dependencies]
|
||||
@@ -28,6 +28,8 @@ opentelemetry-semantic-conventions = "^0"
|
||||
clap = "^3"
|
||||
async-std = { version = "^1", features = ["unstable"], optional = true }
|
||||
tokio = { version = "^1", features = ["full"], optional = true }
|
||||
tokio-stream = { version = "^0", features = ["net"], optional = true }
|
||||
tokio-util = { version = "^0", features = ["compat"], optional = true}
|
||||
async-tungstenite = { version = "^0", features = ["async-tls"] }
|
||||
directories = "^4"
|
||||
capnp = "^0"
|
||||
@@ -47,6 +49,7 @@ bugsalot = "^0"
|
||||
flume = { version = "^0", features = ["async"] }
|
||||
rpassword = "^6"
|
||||
hostname = "^0"
|
||||
stop-token = { version = "^0", default-features = false }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
windows-service = "^0"
|
||||
|
@@ -2,16 +2,17 @@ use crate::tools::*;
|
||||
use crate::veilid_client_capnp::*;
|
||||
use capnp::capability::Promise;
|
||||
use capnp_rpc::{pry, rpc_twoparty_capnp, twoparty, RpcSystem};
|
||||
use cfg_if::*;
|
||||
use failure::*;
|
||||
use futures::io::AsyncReadExt;
|
||||
use futures::FutureExt as FuturesFutureExt;
|
||||
use futures::StreamExt;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::net::SocketAddr;
|
||||
use std::rc::Rc;
|
||||
use stop_token::future::FutureExt;
|
||||
use stop_token::*;
|
||||
use tracing::*;
|
||||
use veilid_core::xx::Eventual;
|
||||
use veilid_core::*;
|
||||
|
||||
#[derive(Fail, Debug)]
|
||||
@@ -236,7 +237,7 @@ type ClientApiAllFuturesJoinHandle =
|
||||
struct ClientApiInner {
|
||||
veilid_api: veilid_core::VeilidAPI,
|
||||
registration_map: Rc<RefCell<RegistrationMap>>,
|
||||
stop: Eventual,
|
||||
stop: Option<StopSource>,
|
||||
join_handle: Option<ClientApiAllFuturesJoinHandle>,
|
||||
}
|
||||
|
||||
@@ -251,7 +252,7 @@ impl ClientApi {
|
||||
inner: RefCell::new(ClientApiInner {
|
||||
veilid_api,
|
||||
registration_map: Rc::new(RefCell::new(RegistrationMap::new())),
|
||||
stop: Eventual::new(),
|
||||
stop: Some(StopSource::new()),
|
||||
join_handle: None,
|
||||
}),
|
||||
})
|
||||
@@ -266,7 +267,7 @@ impl ClientApi {
|
||||
trace!("ClientApi stop ignored");
|
||||
return;
|
||||
}
|
||||
inner.stop.resolve();
|
||||
drop(inner.stop.take());
|
||||
inner.join_handle.take().unwrap()
|
||||
};
|
||||
trace!("ClientApi::stop: waiting for stop");
|
||||
@@ -286,15 +287,32 @@ impl ClientApi {
|
||||
debug!("Client API listening on: {:?}", bind_addr);
|
||||
|
||||
// Process the incoming accept stream
|
||||
// xxx switch to stoptoken and use stream wrapper for tokio
|
||||
let mut incoming = listener.incoming();
|
||||
let stop = self.inner.borrow().stop.clone();
|
||||
cfg_if! {
|
||||
if #[cfg(feature="rt-async-std")] {
|
||||
let mut incoming_stream = listener.incoming();
|
||||
} else if #[cfg(feature="rt-tokio")] {
|
||||
let mut incoming_stream = tokio_stream::wrappers::TcpListenerStream::new(listener);
|
||||
}
|
||||
}
|
||||
|
||||
let stop_token = self.inner.borrow().stop.as_ref().unwrap().token();
|
||||
let incoming_loop = async move {
|
||||
while let Some(stream_result) = stop.instance_none().race(incoming.next()).await {
|
||||
while let Ok(Some(stream_result)) =
|
||||
incoming_stream.next().timeout_at(stop_token.clone()).await
|
||||
{
|
||||
let stream = stream_result?;
|
||||
stream.set_nodelay(true)?;
|
||||
// xxx use tokio split code too
|
||||
let (reader, writer) = stream.split();
|
||||
cfg_if! {
|
||||
if #[cfg(feature="rt-async-std")] {
|
||||
use futures::AsyncReadExt;
|
||||
let (reader, writer) = stream.split();
|
||||
} else if #[cfg(feature="rt-tokio")] {
|
||||
use tokio_util::compat::*;
|
||||
let (reader, writer) = stream.into_split();
|
||||
let reader = reader.compat();
|
||||
let writer = writer.compat_write();
|
||||
}
|
||||
}
|
||||
let network = twoparty::VatNetwork::new(
|
||||
reader,
|
||||
writer,
|
||||
|
@@ -154,7 +154,7 @@ pub async fn run_veilid_server_internal(
|
||||
veilid_api.shutdown().await;
|
||||
|
||||
// Wait for update receiver to exit
|
||||
update_receiver_jh.await;
|
||||
let _ = update_receiver_jh.await;
|
||||
|
||||
out
|
||||
}
|
||||
|
@@ -13,9 +13,9 @@ cfg_if! {
|
||||
pub fn spawn_local<F: Future<Output = T> + 'static, T: 'static>(f: F) -> JoinHandle<T> {
|
||||
async_std::task::spawn_local(f)
|
||||
}
|
||||
pub fn spawn_detached_local<F: Future<Output = T> + 'static, T: 'static>(f: F) {
|
||||
let _ = async_std::task::spawn_local(f);
|
||||
}
|
||||
// pub fn spawn_detached_local<F: Future<Output = T> + 'static, T: 'static>(f: F) {
|
||||
// let _ = async_std::task::spawn_local(f);
|
||||
// }
|
||||
pub use async_std::task::sleep;
|
||||
pub use async_std::future::timeout;
|
||||
pub fn block_on<F: Future<Output = T>, T>(f: F) -> T {
|
||||
@@ -33,9 +33,9 @@ cfg_if! {
|
||||
pub fn spawn_local<F: Future<Output = T> + 'static, T: 'static>(f: F) -> JoinHandle<T> {
|
||||
tokio::task::spawn_local(f)
|
||||
}
|
||||
pub fn spawn_detached_local<F: Future<Output = T> + 'static, T: 'static>(f: F) {
|
||||
let _ = tokio::task::spawn_local(f);
|
||||
}
|
||||
// pub fn spawn_detached_local<F: Future<Output = T> + 'static, T: 'static>(f: F) {
|
||||
// let _ = tokio::task::spawn_local(f);
|
||||
// }
|
||||
pub use tokio::time::sleep;
|
||||
pub use tokio::time::timeout;
|
||||
pub fn block_on<F: Future<Output = T>, T>(f: F) -> T {
|
||||
|
@@ -116,7 +116,7 @@ pub fn run_daemon(settings: Settings, _matches: ArgMatches) -> Result<(), String
|
||||
|
||||
// Terminate the signal stream.
|
||||
handle.close();
|
||||
signals_task.await;
|
||||
let _ = signals_task.await;
|
||||
|
||||
res
|
||||
})
|
||||
|
@@ -64,13 +64,23 @@ impl VeilidLogs {
|
||||
.into();
|
||||
let grpc_endpoint = settingsr.logging.otlp.grpc_endpoint.name.clone();
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature="rt-async-std")] {
|
||||
let exporter = opentelemetry_otlp::new_exporter()
|
||||
.grpcio()
|
||||
.with_endpoint(grpc_endpoint);
|
||||
let batch = opentelemetry::runtime::AsyncStd;
|
||||
} else if #[cfg(feature="rt-tokio")] {
|
||||
let exporter = opentelemetry_otlp::new_exporter()
|
||||
.tonic()
|
||||
.with_endpoint(format!("http://{}", grpc_endpoint));
|
||||
let batch = opentelemetry::runtime::Tokio;
|
||||
}
|
||||
}
|
||||
|
||||
let tracer = opentelemetry_otlp::new_pipeline()
|
||||
.tracing()
|
||||
.with_exporter(
|
||||
opentelemetry_otlp::new_exporter()
|
||||
.grpcio()
|
||||
.with_endpoint(grpc_endpoint),
|
||||
)
|
||||
.with_exporter(exporter)
|
||||
.with_trace_config(opentelemetry::sdk::trace::config().with_resource(
|
||||
Resource::new(vec![KeyValue::new(
|
||||
opentelemetry_semantic_conventions::resource::SERVICE_NAME,
|
||||
@@ -82,7 +92,7 @@ impl VeilidLogs {
|
||||
),
|
||||
)]),
|
||||
))
|
||||
.install_batch(opentelemetry::runtime::AsyncStd)
|
||||
.install_batch(batch)
|
||||
.map_err(|e| format!("failed to install OpenTelemetry tracer: {}", e))?;
|
||||
|
||||
let ignore_list = ignore_list.clone();
|
||||
|
Reference in New Issue
Block a user