Skip to content

Commit

Permalink
Fix error handling for single address
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Mar 15, 2019
1 parent b290273 commit 27c28d6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
7 changes: 7 additions & 0 deletions actix-connect/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion actix-connect/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "actix-connect"
version = "0.1.0"
version = "0.1.1"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix Connector - tcp connector service"
keywords = ["network", "framework", "async", "futures"]
Expand Down
2 changes: 1 addition & 1 deletion actix-connect/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl<T: Address> Future for ConnectorResponse<T> {
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());
}
}
Expand Down
4 changes: 3 additions & 1 deletion actix-connect/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ impl<T: Address> Future for ResolverFuture<T> {
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 {
Expand Down
1 change: 1 addition & 0 deletions actix-connect/src/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fn port(scheme: Option<&str>) -> Option<u16> {
"wss" => Some(443),
"amqp" => Some(5672),
"amqps" => Some(5671),
"sb" => Some(5671),
"mqtt" => Some(1883),
"mqtts" => Some(8883),
_ => None,
Expand Down
11 changes: 10 additions & 1 deletion actix-connect/tests/test_connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 27c28d6

Please sign in to comment.