diff --git a/actix-connect/CHANGES.md b/actix-connect/CHANGES.md index 07c73b71..91a1f8ea 100644 --- a/actix-connect/CHANGES.md +++ b/actix-connect/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [0.2.4] - 2019-09-02 + +* Use arbiter's storage for default async resolver + ## [0.2.3] - 2019-08-05 * Add `ConnectService` and `OpensslConnectService` diff --git a/actix-connect/Cargo.toml b/actix-connect/Cargo.toml index b2dca77c..f81c1c6c 100644 --- a/actix-connect/Cargo.toml +++ b/actix-connect/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-connect" -version = "0.2.3" +version = "0.2.4" authors = ["Nikolay Kim "] description = "Actix Connector - tcp connector service" keywords = ["network", "framework", "async", "futures"] @@ -36,6 +36,7 @@ uri = ["http"] actix-service = "0.4.0" actix-codec = "0.1.2" actix-utils = "0.4.0" +actix-rt = "0.2.5" derive_more = "0.15" either = "1.5.2" futures = "0.1.25" diff --git a/actix-connect/src/lib.rs b/actix-connect/src/lib.rs index bf054f71..ca09d34a 100644 --- a/actix-connect/src/lib.rs +++ b/actix-connect/src/lib.rs @@ -10,8 +10,6 @@ #[macro_use] extern crate log; -use std::cell::RefCell; - mod connect; mod connector; mod error; @@ -32,6 +30,7 @@ pub use self::error::ConnectError; pub use self::resolver::{Resolver, ResolverFactory}; pub use self::service::{ConnectService, ConnectServiceFactory}; +use actix_rt::Arbiter; use actix_service::{NewService, Service, ServiceExt}; use tokio_tcp::TcpStream; @@ -41,16 +40,12 @@ pub fn start_resolver(cfg: ResolverConfig, opts: ResolverOpts) -> AsyncResolver resolver } -thread_local! { - static DEFAULT_RESOLVER: RefCell> = RefCell::new(None); -} +struct DefaultResolver(AsyncResolver); pub(crate) fn get_default_resolver() -> AsyncResolver { - DEFAULT_RESOLVER.with(|cell| { - if let Some(ref resolver) = *cell.borrow() { - return resolver.clone(); - } - + if Arbiter::contains_item::() { + return Arbiter::get_item(|item: &DefaultResolver| item.0.clone()); + } else { let (cfg, opts) = match read_system_conf() { Ok((cfg, opts)) => (cfg, opts), Err(e) => { @@ -62,9 +57,9 @@ pub(crate) fn get_default_resolver() -> AsyncResolver { let (resolver, bg) = AsyncResolver::new(cfg, opts); tokio_current_thread::spawn(bg); - *cell.borrow_mut() = Some(resolver.clone()); + Arbiter::set_item(DefaultResolver(resolver.clone())); resolver - }) + } } pub fn start_default_resolver() -> AsyncResolver {