From 27c28d6597b064e93b6fad3e95f75e880948734e Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Fri, 15 Mar 2019 11:37:51 -0700 Subject: [PATCH] Fix error handling for single address --- actix-connect/CHANGES.md | 7 +++++++ actix-connect/Cargo.toml | 2 +- actix-connect/src/connector.rs | 2 +- actix-connect/src/resolver.rs | 4 +++- actix-connect/src/uri.rs | 1 + actix-connect/tests/test_connect.rs | 11 ++++++++++- 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/actix-connect/CHANGES.md b/actix-connect/CHANGES.md index f562d725..a41a6837 100644 --- a/actix-connect/CHANGES.md +++ b/actix-connect/CHANGES.md @@ -1,5 +1,12 @@ # Changes +## [0.1.1] - 2019-03-15 + +### Fixed + +* Fix error handling for single address + + ## [0.1.0] - 2019-03-14 * Refactor resolver and connector services diff --git a/actix-connect/Cargo.toml b/actix-connect/Cargo.toml index 0ea9eb16..7980480c 100644 --- a/actix-connect/Cargo.toml +++ b/actix-connect/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-connect" -version = "0.1.0" +version = "0.1.1" authors = ["Nikolay Kim "] description = "Actix Connector - tcp connector service" keywords = ["network", "framework", "async", "futures"] diff --git a/actix-connect/src/connector.rs b/actix-connect/src/connector.rs index d7ba944a..33c4ce5b 100644 --- a/actix-connect/src/connector.rs +++ b/actix-connect/src/connector.rs @@ -140,7 +140,7 @@ impl Future for ConnectorResponse { self.req.as_ref().unwrap().host(), self.port, ); - if self.addrs.as_ref().unwrap().is_empty() { + if self.addrs.is_none() || self.addrs.as_ref().unwrap().is_empty() { return Err(err.into()); } } diff --git a/actix-connect/src/resolver.rs b/actix-connect/src/resolver.rs index 7c85d1b2..21d0c281 100644 --- a/actix-connect/src/resolver.rs +++ b/actix-connect/src/resolver.rs @@ -153,7 +153,9 @@ impl Future for ResolverFuture { req.host(), addrs ); - if addrs.len() == 1 { + if addrs.is_empty() { + Err(ConnectError::NoRecords) + } else if addrs.len() == 1 { req.addr = Some(either::Either::Left(addrs.pop_front().unwrap())); Ok(Async::Ready(req)) } else { diff --git a/actix-connect/src/uri.rs b/actix-connect/src/uri.rs index 98da805e..5f5f15de 100644 --- a/actix-connect/src/uri.rs +++ b/actix-connect/src/uri.rs @@ -26,6 +26,7 @@ fn port(scheme: Option<&str>) -> Option { "wss" => Some(443), "amqp" => Some(5672), "amqps" => Some(5671), + "sb" => Some(5671), "mqtt" => Some(1883), "mqtts" => Some(8883), _ => None, diff --git a/actix-connect/tests/test_connect.rs b/actix-connect/tests/test_connect.rs index f2ec467a..5c27bd9a 100644 --- a/actix-connect/tests/test_connect.rs +++ b/actix-connect/tests/test_connect.rs @@ -43,13 +43,22 @@ fn test_static_str() { )) .unwrap(); let mut conn = srv - .block_on(lazy(|| Ok::<_, ()>(actix_connect::new_connector(resolver)))) + .block_on(lazy(|| { + Ok::<_, ()>(actix_connect::new_connector(resolver.clone())) + })) .unwrap(); let con = srv .block_on(conn.call(Connect::with("10", srv.addr()))) .unwrap(); assert_eq!(con.peer_addr().unwrap(), srv.addr()); + + let connect = Connect::new(srv.host().to_owned()); + let mut conn = srv + .block_on(lazy(|| Ok::<_, ()>(actix_connect::new_connector(resolver)))) + .unwrap(); + let con = srv.block_on(conn.call(connect)); + assert!(con.is_err()); } #[test]